Fix/check extension running scripts
Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all
Unified · Split
| @@ -421,6 +421,12 @@ QString ScriptEngine::getFilename() const { · 420 unmodified lines | |||
| 421 | return lastPart; | 421 | return lastPart; |
| 422 | } | 422 | } |
| 423 | 423 | ||
| 424 | bool 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 | |||
| 424 | void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { | 430 | void 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() behavior | 446 | 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) { |