History

Add function hasValidScriptSuffix and check if script extensions are JavaScript or JSON files

Liv committed 9 years ago

Commit e9fac381 parent 1fa3e6b2 files · +16 −0Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+15−0
@@ -425,6 +425,15 @@ QString ScriptEngine::getFilename() const { · 424 unmodified lines
425425 return lastPart;
426426 }
427427
428+bool ScriptEngine::hasValidScriptSuffix(const QString& scriptFileName) {
429+ QFileInfo fileInfo(scriptFileName);
430+ QString scriptSuffixToLower = fileInfo.completeSuffix().toLower();
431+ if (scriptSuffixToLower == "js" || scriptSuffixToLower == "json") {
432+ return true;
433+ }
434+ return false;
435+}
436+
428437 void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
429438 if (_isRunning) {
430439 return;
@@ -434,6 +443,12 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 3 unmodified lines
434443 _fileNameString = url.toString();
435444 _isReloading = reload;
436445
446+ // Check that script is an actual script
447+ if (!hasValidScriptSuffix(_fileNameString)) {
448+ qCDebug(scriptengine) << "File extension of file: " + _fileNameString + " is not a currently supported script type";
449+ return;
450+ }
451+
437452 const auto maxRetries = 0; // for consistency with previous scriptCache->getScript() behavior
438453 auto scriptCache = DependencyManager::get<ScriptCache>();
439454 scriptCache->getScriptContents(url.toString(), [this](const QString& url, const QString& scriptContents, bool isURL, bool success, const QString&status) {