History

Merge pull request #10536 from misslivirose/fix/check-extension-running-scripts

Fix/check extension running scripts

Chris Collins committed 9 years ago

Commit f8b92b62 parents b46ff07 b2bbf212 files · +14 −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+13−0
@@ -421,6 +421,12 @@ QString ScriptEngine::getFilename() const { · 420 unmodified lines
421 return lastPart;421 return lastPart;
422}422}
423 423
424bool ScriptEngine::hasValidScriptSuffix(const QString& scriptFileName) {
425 QFileInfo fileInfo(scriptFileName);
426 QString scriptSuffixToLower = fileInfo.completeSuffix().toLower();
427 return scriptSuffixToLower.contains(QString("js"), Qt::CaseInsensitive);
428}
429
424void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {430void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
425 if (_isRunning) {431 if (_isRunning) {
426 return;432 return;
@@ -430,6 +436,13 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 3 unmodified lines
430 _fileNameString = url.toString();436 _fileNameString = url.toString();
431 _isReloading = reload;437 _isReloading = reload;
432 438
439 // Check that script has a supported file extension
440 if (!hasValidScriptSuffix(_fileNameString)) {
441 scriptErrorMessage("File extension of file: " + _fileNameString + " is not a currently supported script type");
442 emit errorLoadingScript(_fileNameString);
443 return;
444 }
445
433 const auto maxRetries = 0; // for consistency with previous scriptCache->getScript() behavior446 const auto maxRetries = 0; // for consistency with previous scriptCache->getScript() behavior
434 auto scriptCache = DependencyManager::get<ScriptCache>();447 auto scriptCache = DependencyManager::get<ScriptCache>();
435 scriptCache->getScriptContents(url.toString(), [this](const QString& url, const QString& scriptContents, bool isURL, bool success, const QString&status) {448 scriptCache->getScriptContents(url.toString(), [this](const QString& url, const QString& scriptContents, bool isURL, bool success, const QString&status) {