Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all
Unified · Split
| @@ -425,6 +425,15 @@ QString ScriptEngine::getFilename() const { · 424 unmodified lines | |||
| 425 | return lastPart; | 425 | return lastPart; |
| 426 | } | 426 | } |
| 427 | 427 | ||
| 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 | |||
| 428 | void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { | 437 | void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { |
| 429 | if (_isRunning) { | 438 | if (_isRunning) { |
| 430 | return; | 439 | return; |
| @@ -434,6 +443,12 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 3 unmodified lines | |||
| 434 | _fileNameString = url.toString(); | 443 | _fileNameString = url.toString(); |
| 435 | _isReloading = reload; | 444 | _isReloading = reload; |
| 436 | 445 | ||
| 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 | |||
| 437 | const auto maxRetries = 0; // for consistency with previous scriptCache->getScript() behavior | 452 | const auto maxRetries = 0; // for consistency with previous scriptCache->getScript() behavior |
| 438 | auto scriptCache = DependencyManager::get<ScriptCache>(); | 453 | auto scriptCache = DependencyManager::get<ScriptCache>(); |
| 439 | scriptCache->getScriptContents(url.toString(), [this](const QString& url, const QString& scriptContents, bool isURL, bool success, const QString&status) { | 454 | scriptCache->getScriptContents(url.toString(), [this](const QString& url, const QString& scriptContents, bool isURL, bool success, const QString&status) { |