more strict in package resolution
also resolve js files too
This commit is contained in:
parent
b1c49c5d44
commit
6d65ece95a
@ -44,30 +44,44 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QQmlAbstractUrlInterceptor::QmlFile:
|
case QQmlAbstractUrlInterceptor::QmlFile:
|
||||||
|
case QQmlAbstractUrlInterceptor::JavaScriptFile:
|
||||||
|
//asked a file inside a package: let's rewrite the url!
|
||||||
if (path.path().startsWith(m_package.path())) {
|
if (path.path().startsWith(m_package.path())) {
|
||||||
//qDebug() << "Found URL in package" << path;
|
qDebug() << "Found URL in package" << path;
|
||||||
QStringList components = path.toLocalFile().split("/");
|
|
||||||
if (components.count() < 2) {
|
//tries to isolate the relative path asked relative to the contentsPrefixPath: like ui/foo.qml
|
||||||
return path;
|
QString relativePath;
|
||||||
|
foreach (const QString &prefix, m_package.contentsPrefixPaths()) {
|
||||||
|
if (path.path().startsWith(m_package.path()+prefix)) {
|
||||||
|
//obtain a string in the form ui/foo/bar/baz.qml
|
||||||
|
relativePath = path.path().mid(QString(m_package.path()+prefix).length());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
QString filename = components.last();
|
|
||||||
components.pop_back();
|
|
||||||
QString type = components.last();
|
|
||||||
if (type == "ui" || type == "config") {
|
|
||||||
//qDebug() << "Returning" << QUrl::fromLocalFile(m_package.filePath(type.toLatin1(), filename));
|
|
||||||
return QUrl::fromLocalFile(m_package.filePath(type.toLatin1(), filename));
|
|
||||||
}
|
}
|
||||||
|
//should never happen
|
||||||
|
Q_ASSERT(!relativePath.isEmpty());
|
||||||
|
|
||||||
|
QStringList components = relativePath.split("/");
|
||||||
|
Q_ASSERT(components.count() >= 2);
|
||||||
|
|
||||||
|
components.pop_front();
|
||||||
|
//obtain a string in the form foo/bar/baz.qml, ui/ gets discarded
|
||||||
|
QString filename = components.join("/");
|
||||||
|
|
||||||
|
//qDebug() << "Returning" << QUrl::fromLocalFile(m_package.filePath(prefixForType(type, filename), filename));
|
||||||
|
return QUrl::fromLocalFile(m_package.filePath(prefixForType(type, filename), filename));
|
||||||
|
|
||||||
//forbid to load random absolute paths
|
//forbid to load random absolute paths
|
||||||
} else {
|
} else {
|
||||||
foreach (const QString &import, m_engine->importPathList()) {
|
foreach (const QString &import, m_engine->importPathList()) {
|
||||||
//it's from an import, good
|
//it's from an import, good
|
||||||
//TODO: implement imports whitelist?
|
//TODO: implement imports whitelist?
|
||||||
if (path.path().startsWith(import)) {
|
if (path.path().startsWith(import)) {
|
||||||
// qDebug() << "Found import, access granted";
|
//qDebug() << "Found import, access granted";
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qWarning() << "Access denied for url" << path;
|
qWarning() << "WARNING: Access denied for URL" << path;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -34,6 +34,19 @@ public:
|
|||||||
|
|
||||||
virtual QUrl intercept(const QUrl &path, QQmlAbstractUrlInterceptor::DataType type);
|
virtual QUrl intercept(const QUrl &path, QQmlAbstractUrlInterceptor::DataType type);
|
||||||
|
|
||||||
|
static inline QByteArray prefixForType(QQmlAbstractUrlInterceptor::DataType type, const QString &fileName)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case QQmlAbstractUrlInterceptor::QmlFile:
|
||||||
|
return "ui";
|
||||||
|
case QQmlAbstractUrlInterceptor::JavaScriptFile:
|
||||||
|
return "scripts";
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Plasma::Package m_package;
|
Plasma::Package m_package;
|
||||||
QQmlEngine *m_engine;
|
QQmlEngine *m_engine;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user