History

Fix console errors for javascript: urls

Zander Otavka committed 10 years ago

Commit a826f4e1 parent f9b6db11 file · +9 −4Browse files

Showing the changes to libraries/script-engine/src/ScriptCache.cpp (1 of 1 file). Show all

Unified · Split

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