allow scripts on the web to refer to local libraries with /~/
Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all
Unified · Split
| @@ -982,7 +982,18 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 981 unmodified lines | |||
| 982 | // Do NOT use PreferLocalFile as its behavior is unpredictable (e.g., on defaultScriptsLocation()) | 982 | // Do NOT use PreferLocalFile as its behavior is unpredictable (e.g., on defaultScriptsLocation()) |
| 983 | const auto strippingFlags = QUrl::RemoveFilename | QUrl::RemoveQuery | QUrl::RemoveFragment; | 983 | const auto strippingFlags = QUrl::RemoveFilename | QUrl::RemoveQuery | QUrl::RemoveFragment; |
| 984 | for (QString file : includeFiles) { | 984 | for (QString file : includeFiles) { |
| 985 | QUrl thisURL { resolvePath(file) }; | 985 | QUrl thisURL; |
| 986 | if (file.startsWith("/~/")) { | ||
| 987 | thisURL = expandScriptUrl(QUrl::fromLocalFile(expandScriptPath(file))); | ||
| 988 | QUrl defaultScriptsLoc = defaultScriptsLocation(); | ||
| 989 | if (!defaultScriptsLoc.isParentOf(thisURL)) { | ||
| 990 | qDebug() << "ScriptEngine::include -- skipping" << file << "-- outside of standard libraries"; | ||
| 991 | continue; | ||
| 992 | } | ||
| 993 | } else { | ||
| 994 | thisURL = resolvePath(file); | ||
| 995 | } | ||
| 996 | |||
| 986 | if (!_includedURLs.contains(thisURL)) { | 997 | if (!_includedURLs.contains(thisURL)) { |
| 987 | if (!currentSandboxURL.isEmpty() && (thisURL.scheme() == "file") && | 998 | if (!currentSandboxURL.isEmpty() && (thisURL.scheme() == "file") && |
| 988 | ( | 999 | ( |