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

Fix/check extension running scripts
This commit is contained in:
Chris Collins 2017-05-23 22:15:50 -07:00 committed by GitHub
commit f8b92b6666
2 changed files with 14 additions and 0 deletions

View file

@ -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) {

View file

@ -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; }