aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-02-25 16:24:17 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-03-02 21:50:34 +0000
commit1ddf33ac4da4f34451393dfac6caae580e965fc7 (patch)
tree2765e217914e3373cf03f4e40cbd00449929cfdc /tests
parent8858125b2439e24bcdcc7b27d9e28b99dcf0358b (diff)
QML: Explicitly reject malformed file imports
You cannot just pass a resource path or absolute path. We expect a URL after all. A relative path is a relative URL, so you can pass that. Fixes: QTBUG-98181 Change-Id: I010bc08b8cb0ff06712f7b0353955bee96ae36c1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 1240a440f29762850a9206bdf9961cebe015c1fa) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlimport/data/absoluteImport.qml4
-rw-r--r--tests/auto/qml/qqmlimport/data/absoluteResourceImport.qml4
-rw-r--r--tests/auto/qml/qqmlimport/data/relativeResourceImport.qml4
-rw-r--r--tests/auto/qml/qqmlimport/tst_qqmlimport.cpp32
4 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlimport/data/absoluteImport.qml b/tests/auto/qml/qqmlimport/data/absoluteImport.qml
new file mode 100644
index 0000000000..d182fe5b71
--- /dev/null
+++ b/tests/auto/qml/qqmlimport/data/absoluteImport.qml
@@ -0,0 +1,4 @@
+import "/foo/bar/baz"
+
+QtObject {}
+
diff --git a/tests/auto/qml/qqmlimport/data/absoluteResourceImport.qml b/tests/auto/qml/qqmlimport/data/absoluteResourceImport.qml
new file mode 100644
index 0000000000..74b98664aa
--- /dev/null
+++ b/tests/auto/qml/qqmlimport/data/absoluteResourceImport.qml
@@ -0,0 +1,4 @@
+import ":/absolute/resource/path"
+
+QtObject {}
+
diff --git a/tests/auto/qml/qqmlimport/data/relativeResourceImport.qml b/tests/auto/qml/qqmlimport/data/relativeResourceImport.qml
new file mode 100644
index 0000000000..6a7e2b7ea5
--- /dev/null
+++ b/tests/auto/qml/qqmlimport/data/relativeResourceImport.qml
@@ -0,0 +1,4 @@
+import ":relative/resource/path"
+
+QtObject {}
+
diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
index f52b01cf04..7e1e6c44d4 100644
--- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
+++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
@@ -59,6 +59,8 @@ private slots:
void cleanup();
void envResourceImportPath();
void preferResourcePath();
+ void invalidFileImport_data();
+ void invalidFileImport();
};
void tst_QQmlImport::cleanup()
@@ -104,6 +106,36 @@ void tst_QQmlImport::preferResourcePath()
QCOMPARE(o->objectName(), "right");
}
+void tst_QQmlImport::invalidFileImport_data()
+{
+ QTest::addColumn<QString>("file");
+ QTest::addColumn<QString>("import");
+ QTest::addRow("file absolute")
+ << QStringLiteral("absoluteImport.qml")
+ << QStringLiteral("/foo/bar/baz");
+ QTest::addRow("resource absolute")
+ << QStringLiteral("absoluteResourceImport.qml")
+ << QStringLiteral(":/absolute/resource/path");
+ QTest::addRow("resource relative")
+ << QStringLiteral("relativeResourceImport.qml")
+ << QStringLiteral(":relative/resource/path");
+}
+
+void tst_QQmlImport::invalidFileImport()
+{
+ QFETCH(QString, file);
+ QFETCH(QString, import);
+
+ QQmlEngine engine;
+
+ QQmlComponent component(&engine, testFileUrl(file));
+ QVERIFY(component.isError());
+ QVERIFY(component.errorString().contains(
+ QStringLiteral("\"%1\" is not a valid import URL. "
+ "You can pass relative paths or URLs with schema, "
+ "but not absolute paths or resource paths.").arg(import)));
+}
+
void tst_QQmlImport::testDesignerSupported()
{
QQuickView *window = new QQuickView();