From a826f4eca1c689ec641b0f43393adab0fa73fe46 Mon Sep 17 00:00:00 2001 From: Zander Otavka Date: Wed, 3 Aug 2016 15:55:51 -0700 Subject: [PATCH] Fix console errors for javascript: urls --- libraries/script-engine/src/ScriptCache.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libraries/script-engine/src/ScriptCache.cpp b/libraries/script-engine/src/ScriptCache.cpp index d80baf9a7b..40234e8134 100644 --- a/libraries/script-engine/src/ScriptCache.cpp +++ b/libraries/script-engine/src/ScriptCache.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -109,17 +110,20 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable QUrl unnormalizedURL(scriptOrURL); 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) - if (unnormalizedURL.scheme().isEmpty() && scriptOrURL.simplified().replace(" ", "").contains("(function(){")) { + // 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) + if (unnormalizedURL.scheme().isEmpty() && + scriptOrURL.simplified().replace(" ", "").contains(QRegularExpression(R"(\(function\([a-z]?[\w,]*\){)"))) { contentAvailable(scriptOrURL, scriptOrURL, false, true); return; } // give a similar treatment to javacript: urls if (unnormalizedURL.scheme() == "javascript") { - QString contents{ scriptOrURL }; - contents.replace(QRegExp("^javascript:"), ""); + QString contents { scriptOrURL }; + contents.replace(QRegularExpression("^javascript:"), ""); contentAvailable(scriptOrURL, contents, false, true); + return; } Lock lock(_containerLock); @@ -140,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() << "]"; #endif auto request = ResourceManager::createResourceRequest(nullptr, url); + Q_ASSERT(request); request->setCacheEnabled(!forceDownload); connect(request, &ResourceRequest::finished, this, &ScriptCache::scriptContentAvailable); request->send();