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/qml | |
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/qml')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 12 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp | 24 |
4 files changed, 20 insertions, 31 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 |