Showing the changes to libraries/script-engine/src/ScriptCache.cpp (1 of 1 file). Show all
Unified · Split
| @@ -18,6 +18,7 @@ · 17 unmodified lines | ||
| 18 | 18 | #include <QNetworkReply> |
| 19 | 19 | #include <QObject> |
| 20 | 20 | #include <QThread> |
| 21 | +#include <QRegularExpression> | |
| 21 | 22 | |
| 22 | 23 | #include <assert.h> |
| 23 | 24 | #include <SharedUtil.h> |
| @@ -109,17 +110,20 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable · 85 unmodified lines | ||
| 109 | 110 | QUrl unnormalizedURL(scriptOrURL); |
| 110 | 111 | QUrl url = ResourceManager::normalizeURL(unnormalizedURL); |
| 111 | 112 | |
| 112 | − // 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) | |
| 113 | − if (unnormalizedURL.scheme().isEmpty() && scriptOrURL.simplified().replace(" ", "").contains("(function(){")) { | |
| 113 | + // attempt to determine if this is a URL to a script, or if this is actually a script itself (which is valid in the | |
| 114 | + // entityScript use case) | |
| 115 | + if (unnormalizedURL.scheme().isEmpty() && | |
| 116 | + scriptOrURL.simplified().replace(" ", "").contains(QRegularExpression(R"(\(function\([a-z]?[\w,]*\){)"))) { | |
| 114 | 117 | contentAvailable(scriptOrURL, scriptOrURL, false, true); |
| 115 | 118 | return; |
| 116 | 119 | } |
| 117 | 120 | |
| 118 | 121 | // give a similar treatment to javacript: urls |
| 119 | 122 | if (unnormalizedURL.scheme() == "javascript") { |
| 120 | − QString contents{ scriptOrURL }; | |
| 121 | − contents.replace(QRegExp("^javascript:"), ""); | |
| 123 | + QString contents { scriptOrURL }; | |
| 124 | + contents.replace(QRegularExpression("^javascript:"), ""); | |
| 122 | 125 | contentAvailable(scriptOrURL, contents, false, true); |
| 126 | + return; | |
| 123 | 127 | } |
| 124 | 128 | |
| 125 | 129 | Lock lock(_containerLock); |
| @@ -140,6 +144,7 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable · 14 unmodified lines | ||
| 140 | 144 | qCDebug(scriptengine) << "about to call: ResourceManager::createResourceRequest(this, url); on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]"; |
| 141 | 145 | #endif |
| 142 | 146 | auto request = ResourceManager::createResourceRequest(nullptr, url); |
| 147 | + Q_ASSERT(request); | |
| 143 | 148 | request->setCacheEnabled(!forceDownload); |
| 144 | 149 | connect(request, &ResourceRequest::finished, this, &ScriptCache::scriptContentAvailable); |
| 145 | 150 | request->send(); |