diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-15 17:53:16 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-22 18:37:52 +0200 |
commit | 0a1e4cc7ec7548f6273befff9cdddb0bc7a58961 (patch) | |
tree | bf8b7ae725ac332fa59bd9058cc479018aca147d /tests/auto | |
parent | 4e266103ad8b75d71fb176a2f774faf71997123d (diff) |
Do not resolve URLs when assigning them to a property
We don't know in advance if a URL is part of the source code and should
be relative to the current element, or if it is part of the application
data and should not be touched.
[ChangeLog][QtQml][Important Behavior Changes] URLs are not resolved or
intercepted anymore when assigning them to a "url" property. Instead
they are resolved and possibly intercepted when used to access an actual
resource.
Fixes: QTBUG-76879
Change-Id: Iaa2385aff2c13aa71a12e57385d9afb5dc60a073
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto')
11 files changed, 35 insertions, 51 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index cb1dc89441..deca005431 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -481,7 +481,7 @@ void tst_qqmlecmascript::assignBasicTypes() QCOMPARE(object->boolProperty(), true); QCOMPARE(object->variantProperty(), QVariant("Hello World!")); QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2f)); - QCOMPARE(object->urlProperty(), component.url().resolved(QUrl("main.qml"))); + QCOMPARE(object->urlProperty(), QUrl("main.qml")); delete object; } { @@ -510,7 +510,7 @@ void tst_qqmlecmascript::assignBasicTypes() QCOMPARE(object->boolProperty(), true); QCOMPARE(object->variantProperty(), QVariant("Hello World!")); QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2f)); - QCOMPARE(object->urlProperty(), component.url().resolved(QUrl("main.qml"))); + QCOMPARE(object->urlProperty(), QUrl("main.qml")); delete object; } } @@ -6036,10 +6036,10 @@ void tst_qqmlecmascript::assignSequenceTypes() MySequenceConversionObject *msco4 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco4")); MySequenceConversionObject *msco5 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco5")); QVERIFY(msco1 != nullptr && msco2 != nullptr && msco3 != nullptr && msco4 != nullptr && msco5 != nullptr); - QCOMPARE(msco1->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html")))); - QCOMPARE(msco2->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html")))); - QCOMPARE(msco3->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html")) << QUrl(testFileUrl("example2.html")))); - QCOMPARE(msco4->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html")) << QUrl(testFileUrl("example2.html")))); + QCOMPARE(msco1->urlListProperty(), (QList<QUrl>() << QUrl("example.html"))); + QCOMPARE(msco2->urlListProperty(), (QList<QUrl>() << QUrl("example.html"))); + QCOMPARE(msco3->urlListProperty(), (QList<QUrl>() << QUrl("example.html") << QUrl("example2.html"))); + QCOMPARE(msco4->urlListProperty(), (QList<QUrl>() << QUrl("example.html") << QUrl("example2.html"))); QCOMPARE(msco5->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html")) << QUrl(testFileUrl("example2.html")))); delete object; } diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index 39e986f12a..ff8d6e2b2c 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -799,7 +799,6 @@ void tst_qqmlengine::urlInterceptor_data() { QTest::addColumn<QUrl>("testFile"); QTest::addColumn<QList<QQmlAbstractUrlInterceptor::DataType> >("interceptionPoint"); - QTest::addColumn<QString>("expectedFilePath"); QTest::addColumn<QString>("expectedChildString"); QTest::addColumn<QString>("expectedScriptString"); QTest::addColumn<QString>("expectedResolvedUrl"); @@ -808,7 +807,6 @@ void tst_qqmlengine::urlInterceptor_data() QTest::newRow("InterceptTypes") << testFileUrl("interception/types/urlInterceptor.qml") << (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::QmlFile << QQmlAbstractUrlInterceptor::JavaScriptFile << QQmlAbstractUrlInterceptor::UrlString) - << testFileUrl("interception/types/intercepted/doesNotExist.file").toString() << QStringLiteral("intercepted") << QStringLiteral("intercepted") << testFileUrl("interception/types/intercepted/doesNotExist.file").toString() @@ -817,7 +815,6 @@ void tst_qqmlengine::urlInterceptor_data() QTest::newRow("InterceptQmlDir") << testFileUrl("interception/qmldir/urlInterceptor.qml") << (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::QmldirFile << QQmlAbstractUrlInterceptor::UrlString) - << testFileUrl("interception/qmldir/intercepted/doesNotExist.file").toString() << QStringLiteral("intercepted") << QStringLiteral("base file") << testFileUrl("interception/qmldir/intercepted/doesNotExist.file").toString() @@ -826,7 +823,6 @@ void tst_qqmlengine::urlInterceptor_data() QTest::newRow("InterceptModule")//just a Test{}, needs to intercept the module import for it to work << testFileUrl("interception/module/urlInterceptor.qml") << (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::QmldirFile ) - << testFileUrl("interception/module/intercepted/doesNotExist.file").toString() << QStringLiteral("intercepted") << QStringLiteral("intercepted") << testFileUrl("interception/module/intercepted/doesNotExist.file").toString() @@ -835,7 +831,6 @@ void tst_qqmlengine::urlInterceptor_data() QTest::newRow("InterceptStrings") << testFileUrl("interception/strings/urlInterceptor.qml") << (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::UrlString) - << testFileUrl("interception/strings/intercepted/doesNotExist.file").toString() << QStringLiteral("base file") << QStringLiteral("base file") << testFileUrl("interception/strings/intercepted/doesNotExist.file").toString() @@ -844,7 +839,6 @@ void tst_qqmlengine::urlInterceptor_data() QTest::newRow("InterceptIncludes") << testFileUrl("interception/includes/urlInterceptor.qml") << (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::JavaScriptFile) - << testFileUrl("interception/includes/doesNotExist.file").toString() << QStringLiteral("base file") << QStringLiteral("intercepted include file") << testFileUrl("interception/includes/doesNotExist.file").toString() @@ -856,7 +850,6 @@ void tst_qqmlengine::urlInterceptor() QFETCH(QUrl, testFile); QFETCH(QList<QQmlAbstractUrlInterceptor::DataType>, interceptionPoint); - QFETCH(QString, expectedFilePath); QFETCH(QString, expectedChildString); QFETCH(QString, expectedScriptString); QFETCH(QString, expectedResolvedUrl); @@ -873,7 +866,7 @@ void tst_qqmlengine::urlInterceptor() qDebug() << c.errorString(); QVERIFY(o); //Test a URL as a property initialization - QCOMPARE(o->property("filePath").toString(), expectedFilePath); + QCOMPARE(o->property("filePath").toString(), QUrl("doesNotExist.file").toString()); //Test a URL as a Type location QCOMPARE(o->property("childString").toString(), expectedChildString); //Test a URL as a Script location diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 411ff7df56..177f7554f7 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -814,7 +814,7 @@ void tst_qqmllanguage::assignBasicTypes() QCOMPARE(object->vector2Property(), QVector2D(2, 3)); QCOMPARE(object->vector4Property(), QVector4D(10, 1, 2.2f, 2.3f)); const QUrl encoded = QUrl::fromEncoded("main.qml?with%3cencoded%3edata", QUrl::TolerantMode); - QCOMPARE(object->urlProperty(), component.url().resolved(encoded)); + QCOMPARE(object->urlProperty(), encoded); QVERIFY(object->objectProperty() != nullptr); MyTypeObject *child = qobject_cast<MyTypeObject *>(object->objectProperty()); QVERIFY(child != nullptr); @@ -1293,7 +1293,7 @@ void tst_qqmllanguage::bindTypeToJSValue() MyQmlObject *object = root->findChild<MyQmlObject *>("urlProperty"); QJSValue value = object->qjsvalue(); const QUrl encoded = QUrl::fromEncoded("main.qml?with%3cencoded%3edata", QUrl::TolerantMode); - QCOMPARE(value.toString(), component.url().resolved(encoded).toString()); + QCOMPARE(value.toString(), encoded.toString()); } { MyQmlObject *object = root->findChild<MyQmlObject *>("objectProperty"); QJSValue value = object->qjsvalue(); @@ -1468,7 +1468,7 @@ void tst_qqmllanguage::dynamicProperties() QCOMPARE(object->property("doubleProperty"), QVariant(-10.1)); QCOMPARE(object->property("realProperty"), QVariant((qreal)-19.9)); QCOMPARE(object->property("stringProperty"), QVariant("Hello World!")); - QCOMPARE(object->property("urlProperty"), QVariant(testFileUrl("main.qml"))); + QCOMPARE(object->property("urlProperty"), QVariant(QUrl("main.qml"))); QCOMPARE(object->property("colorProperty"), QVariant(QColor("red"))); QCOMPARE(object->property("dateProperty"), QVariant(QDate(1945, 9, 2))); QCOMPARE(object->property("varProperty"), QVariant("Hello World!")); diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index 26bfd731e6..ae9ced909f 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -1396,29 +1396,25 @@ void tst_qqmlproperty::write() { PropertyObject o; QQmlProperty p(&o, "url"); + const QUrl url = QUrl("main.qml"); - QCOMPARE(p.write(QUrl("main.qml")), true); - QCOMPARE(o.url(), QUrl("main.qml")); + QCOMPARE(p.write(url), true); + QCOMPARE(o.url(), url); QQmlProperty p2(&o, "url", engine.rootContext()); - QUrl result = engine.baseUrl().resolved(QUrl("main.qml")); - QVERIFY(result != QUrl("main.qml")); - - QCOMPARE(p2.write(QUrl("main.qml")), true); - QCOMPARE(o.url(), result); + QCOMPARE(p2.write(url), true); + QCOMPARE(o.url(), url); } { // static PropertyObject o; + const QUrl url = QUrl("main.qml"); - QCOMPARE(QQmlProperty::write(&o, "url", QUrl("main.qml")), true); - QCOMPARE(o.url(), QUrl("main.qml")); - - QUrl result = engine.baseUrl().resolved(QUrl("main.qml")); - QVERIFY(result != QUrl("main.qml")); + QCOMPARE(QQmlProperty::write(&o, "url", url), true); + QCOMPARE(o.url(), url); - QCOMPARE(QQmlProperty::write(&o, "url", QUrl("main.qml"), engine.rootContext()), true); - QCOMPARE(o.url(), result); + QCOMPARE(QQmlProperty::write(&o, "url", url, engine.rootContext()), true); + QCOMPARE(o.url(), url); } // Char/string-property diff --git a/tests/auto/qmltest/animatedimage/tst_animatedimage.qml b/tests/auto/qmltest/animatedimage/tst_animatedimage.qml index e1dab54816..c89717b973 100644 --- a/tests/auto/qmltest/animatedimage/tst_animatedimage.qml +++ b/tests/auto/qmltest/animatedimage/tst_animatedimage.qml @@ -227,7 +227,7 @@ Item { } function test_clearSource() { - compare(clearSource.source, Qt.resolvedUrl(srcImage)) + compare(clearSource.source, srcImage) compare(clearSource.width, 160) compare(clearSource.height, 120) diff --git a/tests/auto/qmltest/borderimage/tst_borderimage.qml b/tests/auto/qmltest/borderimage/tst_borderimage.qml index a4e0a66aa2..a8da0ad9a2 100644 --- a/tests/auto/qmltest/borderimage/tst_borderimage.qml +++ b/tests/auto/qmltest/borderimage/tst_borderimage.qml @@ -162,7 +162,7 @@ Item { } function test_clearSource() { - compare(clearSource.source, Qt.resolvedUrl("colors.png")) + compare(clearSource.source, "colors.png") compare(clearSource.width, 120) compare(clearSource.height, 120) @@ -235,7 +235,7 @@ Item { img.source = row.source; } - compare(img.source, Qt.resolvedUrl(row.source)) + compare(img.source, row.source) compare(img.width, 300) compare(img.height, 300) diff --git a/tests/auto/qmltest/image/tst_image.qml b/tests/auto/qmltest/image/tst_image.qml index f8f0e7b53c..3eaa9b902c 100644 --- a/tests/auto/qmltest/image/tst_image.qml +++ b/tests/auto/qmltest/image/tst_image.qml @@ -185,7 +185,7 @@ Item { } function test_clearSource() { - compare(clearSource.source, Qt.resolvedUrl(srcImage)) + compare(clearSource.source, srcImage) compare(clearSource.width, 59) compare(clearSource.height, 71) diff --git a/tests/auto/qmltest/listview/tst_listview.qml b/tests/auto/qmltest/listview/tst_listview.qml index bea6b45c3a..b939cffcd5 100644 --- a/tests/auto/qmltest/listview/tst_listview.qml +++ b/tests/auto/qmltest/listview/tst_listview.qml @@ -380,11 +380,11 @@ Item { function test_multipleDelegates_data() { return [ { y: 25, type: "Rectangle", value: "red" }, - { y: 75, type: "Image", value: Qt.resolvedUrl("data/logo.png") }, + { y: 75, type: "Image", value: "logo.png" }, { y: 125, type: "Text", value: "Hello" }, { y: 175, type: "Text", value: "World" }, { y: 225, type: "Rectangle", value: "green" }, - { y: 275, type: "Image", value: Qt.resolvedUrl("data/logo.png") }, + { y: 275, type: "Image", value: "logo.png" }, { y: 325, type: "Rectangle", value: "blue" }, { y: 375, type: "Item", value: "" } ] diff --git a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp index 858a685796..504d476dfa 100644 --- a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp +++ b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp @@ -429,7 +429,7 @@ void tst_qquickborderimage::statusChanges_data() QTest::newRow("localfile") << testFileUrl("colors.png").toString() << 1 << false << QQuickImageBase::Ready; QTest::newRow("nofile") << "" << 0 << false << QQuickImageBase::Null; QTest::newRow("nonexistent") << testFileUrl("thisfiledoesnotexist.png").toString() << 1 << false << QQuickImageBase::Error; - QTest::newRow("noprotocol") << QString("thisfiledoesnotexisteither.png") << 2 << false << QQuickImageBase::Error; + QTest::newRow("noprotocol") << QString("thisfiledoesnotexisteither.png") << 1 << false << QQuickImageBase::Error; QTest::newRow("remote") << "/colors.png" << 2 << true << QQuickImageBase::Ready; } diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index a204be8d59..047ca81186 100644 --- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp +++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp @@ -214,18 +214,13 @@ void tst_QQuickLoader::sourceOrComponent_data() QTest::addColumn<QUrl>("sourceUrl"); QTest::addColumn<QString>("errorString"); - auto encodedTestFileUrl = [&](const char *file) - { - return dataDirectoryUrl().resolved(QUrl(file)); - }; - - QTest::newRow("source") << "source" << "source: 'Rect120x60.qml'\n" << testFileUrl("Rect120x60.qml") << ""; - QTest::newRow("source with subdir") << "source" << "source: 'subdir/Test.qml'\n" << testFileUrl("subdir/Test.qml") << ""; - QTest::newRow("source with encoded subdir literal") << "source" << "source: 'subdir%2fTest.qml'\n" << encodedTestFileUrl("subdir%2FTest.qml") << ""; - QTest::newRow("source with encoded subdir optimized binding") << "source" << "source: 'subdir' + '%2fTest.qml'\n" << encodedTestFileUrl("subdir%2FTest.qml") << ""; - QTest::newRow("source with encoded subdir binding") << "source" << "source: encodeURIComponent('subdir/Test.qml')\n" << encodedTestFileUrl("subdir%2FTest.qml") << ""; + QTest::newRow("source") << "source" << "source: 'Rect120x60.qml'\n" << QUrl("Rect120x60.qml") << ""; + QTest::newRow("source with subdir") << "source" << "source: 'subdir/Test.qml'\n" << QUrl("subdir/Test.qml") << ""; + QTest::newRow("source with encoded subdir literal") << "source" << "source: 'subdir%2fTest.qml'\n" << QUrl("subdir%2FTest.qml") << ""; + QTest::newRow("source with encoded subdir optimized binding") << "source" << "source: 'subdir' + '%2fTest.qml'\n" << QUrl("subdir%2FTest.qml") << ""; + QTest::newRow("source with encoded subdir binding") << "source" << "source: encodeURIComponent('subdir/Test.qml')\n" << QUrl("subdir%2FTest.qml") << ""; QTest::newRow("sourceComponent") << "component" << "Component { id: comp; Rectangle { width: 100; height: 50 } }\n sourceComponent: comp\n" << QUrl() << ""; - QTest::newRow("invalid source") << "source" << "source: 'IDontExist.qml'\n" << testFileUrl("IDontExist.qml") + QTest::newRow("invalid source") << "source" << "source: 'IDontExist.qml'\n" << QUrl("IDontExist.qml") << QString(testFileUrl("IDontExist.qml").toString() + ": No such file or directory"); } @@ -809,7 +804,7 @@ void tst_QQuickLoader::deleteComponentCrash() QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); QCoreApplication::processEvents(); QTRY_COMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); - QCOMPARE(loader->source(), testFileUrl("BlueRect.qml")); + QCOMPARE(loader->source(), QUrl("BlueRect.qml")); } void tst_QQuickLoader::nonItem() diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp index d5fea3cb28..e8ea6b5f1a 100644 --- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp +++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp @@ -1360,7 +1360,7 @@ void tst_qquickstates::urlResolution() QVERIFY(myType != nullptr && image1 != nullptr && image2 != nullptr && image3 != nullptr); QQuickItemPrivate::get(myType)->setState("SetImageState"); - QUrl resolved = testFileUrl("Implementation/images/qt-logo.png"); + QUrl resolved = QUrl("images/qt-logo.png"); QCOMPARE(image1->source(), resolved); QCOMPARE(image2->source(), resolved); QCOMPARE(image3->source(), resolved); |