fix problem where canonicalFilePath will strip a trailing slash

This commit is contained in:
Seth Alves 2016-04-29 13:17:28 -07:00 committed by Seth Alves
parent 36e84e6266
commit b28cfd27ec
3 changed files with 13 additions and 12 deletions

View file

@ -874,6 +874,7 @@ QUrl ScriptEngine::resolvePath(const QString& include) const {
} }
// at this point we should have a legitimate fully qualified URL for our parent // at this point we should have a legitimate fully qualified URL for our parent
qDebug() << "ScriptEngine::resolvePath" << parentURL << url;
url = expandScriptUrl(parentURL.resolved(url)); url = expandScriptUrl(parentURL.resolved(url));
return url; return url;
} }

View file

@ -89,13 +89,7 @@ QUrl expandScriptUrl(const QUrl& rawScriptURL) {
// stop something like Script.include(["/~/../Desktop/naughty.js"]); from working // stop something like Script.include(["/~/../Desktop/naughty.js"]); from working
QFileInfo fileInfo(url.toLocalFile()); QFileInfo fileInfo(url.toLocalFile());
#if defined(Q_OS_WIN)
url = QUrl::fromLocalFile(fileInfo.canonicalFilePath().toLower());
#elif defined(Q_OS_OSX)
url = QUrl::fromLocalFile(fileInfo.canonicalFilePath().toLower());
#else
url = QUrl::fromLocalFile(fileInfo.canonicalFilePath()); url = QUrl::fromLocalFile(fileInfo.canonicalFilePath());
#endif
QUrl defaultScriptsLoc = defaultScriptsLocation(); QUrl defaultScriptsLoc = defaultScriptsLocation();
if (!defaultScriptsLoc.isParentOf(url)) { if (!defaultScriptsLoc.isParentOf(url)) {
@ -105,6 +99,9 @@ QUrl expandScriptUrl(const QUrl& rawScriptURL) {
<< defaultScriptsLoc.path(); << defaultScriptsLoc.path();
return rawScriptURL; return rawScriptURL;
} }
if (rawScriptURL.path().endsWith("/") && !url.path().endsWith("/")) {
url.setPath(url.path() + "/");
}
return url; return url;
} }
return normalizedScriptURL; return normalizedScriptURL;

View file

@ -56,12 +56,15 @@ QString findMostRecentFileExtension(const QString& originalFileName, QVector<QSt
} }
QUrl defaultScriptsLocation() { QUrl defaultScriptsLocation() {
#ifdef Q_OS_WIN
return QUrl(("file:///" + QCoreApplication::applicationDirPath()).toLower() + "/scripts");
#elif defined(Q_OS_OSX)
return QUrl(("file://" + QCoreApplication::applicationDirPath() + "/../Resources/scripts").toLower());
#else
// return "http://s3.amazonaws.com/hifi-public"; // return "http://s3.amazonaws.com/hifi-public";
return QUrl("file://" + QCoreApplication::applicationDirPath() + "/scripts"); #ifdef Q_OS_WIN
QString path = QCoreApplication::applicationDirPath() + "/scripts";
#elif defined(Q_OS_OSX)
QString path = QCoreApplication::applicationDirPath() + "/../Resources/scripts";
#else
QString path = QCoreApplication::applicationDirPath() + "/scripts";
#endif #endif
QFileInfo fileInfo(path);
return QUrl::fromLocalFile(fileInfo.canonicalFilePath());
} }