mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-19 08:29:09 +02:00
Merge pull request #8358 from AlexanderOtavka/inline-e-script
Fix parsing of embedded entity scripts
This commit is contained in:
commit
452c0218da
1 changed files with 14 additions and 2 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
@ -109,12 +110,22 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable
|
||||||
QUrl unnormalizedURL(scriptOrURL);
|
QUrl unnormalizedURL(scriptOrURL);
|
||||||
QUrl url = ResourceManager::normalizeURL(unnormalizedURL);
|
QUrl url = ResourceManager::normalizeURL(unnormalizedURL);
|
||||||
|
|
||||||
// attempt to determine if this is a URL to a script, or if this is actually a script itself (which is valid in the entityScript use case)
|
// attempt to determine if this is a URL to a script, or if this is actually a script itself (which is valid in the
|
||||||
if (url.scheme().isEmpty() && scriptOrURL.simplified().replace(" ", "").contains("(function(){")) {
|
// entityScript use case)
|
||||||
|
if (unnormalizedURL.scheme().isEmpty() &&
|
||||||
|
scriptOrURL.simplified().replace(" ", "").contains(QRegularExpression(R"(\(function\([a-z]?[\w,]*\){)"))) {
|
||||||
contentAvailable(scriptOrURL, scriptOrURL, false, true);
|
contentAvailable(scriptOrURL, scriptOrURL, false, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// give a similar treatment to javacript: urls
|
||||||
|
if (unnormalizedURL.scheme() == "javascript") {
|
||||||
|
QString contents { scriptOrURL };
|
||||||
|
contents.replace(QRegularExpression("^javascript:"), "");
|
||||||
|
contentAvailable(scriptOrURL, contents, false, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Lock lock(_containerLock);
|
Lock lock(_containerLock);
|
||||||
if (_scriptCache.contains(url) && !forceDownload) {
|
if (_scriptCache.contains(url) && !forceDownload) {
|
||||||
auto scriptContent = _scriptCache[url];
|
auto scriptContent = _scriptCache[url];
|
||||||
|
@ -133,6 +144,7 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable
|
||||||
qCDebug(scriptengine) << "about to call: ResourceManager::createResourceRequest(this, url); on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
|
qCDebug(scriptengine) << "about to call: ResourceManager::createResourceRequest(this, url); on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
|
||||||
#endif
|
#endif
|
||||||
auto request = ResourceManager::createResourceRequest(nullptr, url);
|
auto request = ResourceManager::createResourceRequest(nullptr, url);
|
||||||
|
Q_ASSERT(request);
|
||||||
request->setCacheEnabled(!forceDownload);
|
request->setCacheEnabled(!forceDownload);
|
||||||
connect(request, &ResourceRequest::finished, this, &ScriptCache::scriptContentAvailable);
|
connect(request, &ResourceRequest::finished, this, &ScriptCache::scriptContentAvailable);
|
||||||
request->send();
|
request->send();
|
||||||
|
|
Loading…
Reference in a new issue