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 | 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 | 430 | void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { |
| 425 | 431 | if (_isRunning) { |
| 426 | 432 | return; |
| @@ -430,6 +436,13 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 3 unmodified lines | ||
| 430 | 436 | _fileNameString = url.toString(); |
| 431 | 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 | 446 | const auto maxRetries = 0; // for consistency with previous scriptCache->getScript() behavior |
| 434 | 447 | auto scriptCache = DependencyManager::get<ScriptCache>(); |
| 435 | 448 | scriptCache->getScriptContents(url.toString(), [this](const QString& url, const QString& scriptContents, bool isURL, bool success, const QString&status) { |