From d73497f136fbfad5d367e5af429adb7d38af6dfe Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Wed, 3 Jul 2019 08:37:16 +0200 Subject: QQmlComponent: Check for existence of engine Avoid a crash when setData or create are called after a user mistakenly used the internal constructor of QQmlComponent which does not take an engine. Fixes: QTBUG-55407 Change-Id: Ia4295d1b044723efce1a95607349561d4f1640da Reviewed-by: Ulf Hermann --- tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index 7c7c7d3bd0..a872cece96 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -121,6 +121,7 @@ private slots: void setNonExistentInitialProperty(); void relativeUrl_data(); void relativeUrl(); + void setDataNoEngineNoSegfault(); private: QQmlEngine engine; @@ -654,6 +655,17 @@ void tst_qqmlcomponent::relativeUrl() QVERIFY2(!component.isError(), qPrintable(component.errorString())); } +void tst_qqmlcomponent::setDataNoEngineNoSegfault() +{ + QQmlEngine eng; + QQmlComponent comp; + QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Must provide an engine before calling setData"); + comp.setData("import QtQuick 1.0; QtObject { }", QUrl("")); + QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Must provide an engine before calling create"); + auto c = comp.create(); + QVERIFY(!c); +} + QTEST_MAIN(tst_qqmlcomponent) #include "tst_qqmlcomponent.moc" -- cgit v1.2.3 From b79b9e35334b3bdd41329f2ea74bc82f3f05ae52 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 3 Jul 2019 09:25:53 +0200 Subject: Create a URL from the import string before adding the qmldir path Otherwise the path might get interpreted as some other part of the URL, for example the host name. Fixes: QTBUG-76441 Change-Id: I3edde96153403962db4576e5af794419c21b49a8 Reviewed-by: Fabian Kosmale Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmltypeloader/data/qrcRootPath.qml | 4 ++++ tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/auto/qml/qqmltypeloader/data/qrcRootPath.qml (limited to 'tests/auto') diff --git a/tests/auto/qml/qqmltypeloader/data/qrcRootPath.qml b/tests/auto/qml/qqmltypeloader/data/qrcRootPath.qml new file mode 100644 index 0000000000..bdbee4eb59 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/qrcRootPath.qml @@ -0,0 +1,4 @@ +import QtQml 2.12 +import "qrc:/" + +QtObject {} diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp index 0c4abf19f4..52c722aac8 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -56,6 +56,7 @@ private slots: void qmlSingletonWithinModule(); void multiSingletonModule(); void implicitComponentModule(); + void qrcRootPathUrl(); }; void tst_QQMLTypeLoader::testLoadComplete() @@ -503,6 +504,13 @@ void tst_QQMLTypeLoader::implicitComponentModule() checkCleanCacheLoad(QLatin1String("implicitComponentModule")); } +void tst_QQMLTypeLoader::qrcRootPathUrl() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("qrcRootPath.qml")); + QCOMPARE(component.status(), QQmlComponent::Ready); +} + QTEST_MAIN(tst_QQMLTypeLoader) #include "tst_qqmltypeloader.moc" -- cgit v1.2.3