mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 07:13:57 +02:00
Merge pull request #10536 from misslivirose/fix/check-extension-running-scripts
Fix/check extension running scripts
This commit is contained in:
commit
f8b92b6666
2 changed files with 14 additions and 0 deletions
|
@ -421,6 +421,12 @@ QString ScriptEngine::getFilename() const {
|
|||
return lastPart;
|
||||
}
|
||||
|
||||
bool ScriptEngine::hasValidScriptSuffix(const QString& scriptFileName) {
|
||||
QFileInfo fileInfo(scriptFileName);
|
||||
QString scriptSuffixToLower = fileInfo.completeSuffix().toLower();
|
||||
return scriptSuffixToLower.contains(QString("js"), Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
||||
if (_isRunning) {
|
||||
return;
|
||||
|
@ -430,6 +436,13 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
|||
_fileNameString = url.toString();
|
||||
_isReloading = reload;
|
||||
|
||||
// Check that script has a supported file extension
|
||||
if (!hasValidScriptSuffix(_fileNameString)) {
|
||||
scriptErrorMessage("File extension of file: " + _fileNameString + " is not a currently supported script type");
|
||||
emit errorLoadingScript(_fileNameString);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto maxRetries = 0; // for consistency with previous scriptCache->getScript() behavior
|
||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||
scriptCache->getScriptContents(url.toString(), [this](const QString& url, const QString& scriptContents, bool isURL, bool success, const QString&status) {
|
||||
|
|
|
@ -146,6 +146,7 @@ public:
|
|||
/// to run... NOTE - this is used by Application currently to load the url. We don't really want it to be exposed
|
||||
/// to scripts. we may not need this to be invokable
|
||||
void loadURL(const QUrl& scriptURL, bool reload);
|
||||
bool hasValidScriptSuffix(const QString& scriptFileName);
|
||||
|
||||
Q_INVOKABLE QString getContext() const;
|
||||
Q_INVOKABLE bool isClientScript() const { return _context == CLIENT_SCRIPT; }
|
||||
|
|
Loading…
Reference in a new issue