aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-06-15 15:48:40 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-06-22 09:10:18 +0200
commit8a3f8595569a920cf2fa811704dec97ae31be15d (patch)
tree84496eca2ae5330492ae54c7cf08531471127e3f
parent64fb25a2acada6d9f0897b7e8db4583de4d8d2be (diff)
Revert "Decode directory separators in source URLs"
This reverts commit 7ec30c51b287159377761338fe6d3b48706d74ee. We don't want to half-decode directory separators on assignment. This just introduces inconsistency down the line. [ChangeLog][QtQml][Important Behavior Changes] Percent-encoded directory separators in URLs are not automatically decoded on assignment to url properties anymore. This was obviously not a good idea to begin with. Fixes: QTBUG-81244 Change-Id: I1938abbe8aada88beff0d628397674255e8b2472 Reviewed-by: Andy Shaw <andy.shaw@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc4
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp7
-rw-r--r--src/qml/qml/qqmlproperty.cpp19
-rw-r--r--tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp3
-rw-r--r--tests/auto/quick/qquickloader/tst_qquickloader.cpp11
5 files changed, 19 insertions, 25 deletions
diff --git a/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc b/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc
index 1040baedc0..f35a56858b 100644
--- a/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc
+++ b/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc
@@ -295,9 +295,7 @@ property is only invoked when the property is reassigned to a different object v
Additionally, URLs may contain encoded characters using the 'percent-encoding' scheme
specified by \l {http://tools.ietf.org/html/rfc3986}{RFC 3986}. These characters
will be preserved within properties of type \c url, to allow QML code to
- construct precise URL values. An exception to this rule is the preemptive
- decoding of directory-separator characters (\c '/') - these characters are decoded
- to allow the URL to be correctly classified.
+ construct precise URL values.
For example, a local file containing a '#' character, which would normally be
interpreted as the beginning of the URL 'fragment' element, can be accessed by
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index cbf243b9c1..61d287fc88 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -451,10 +451,9 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const
break;
case QMetaType::QUrl: {
assertType(QV4::CompiledData::Binding::Type_String);
- QString string = compilationUnit->bindingValueAsString(binding);
- // Encoded dir-separators defeat QUrl processing - decode them first
- string.replace(QLatin1String("%2f"), QLatin1String("/"), Qt::CaseInsensitive);
- QUrl value = string.isEmpty() ? QUrl() : compilationUnit->finalUrl().resolved(QUrl(string));
+ const QString string = compilationUnit->bindingValueAsString(binding);
+ QUrl value = string.isEmpty() ? QUrl()
+ : compilationUnit->finalUrl().resolved(QUrl(string));
// Apply URL interceptor
value = engine->interceptUrl(value, QQmlAbstractUrlInterceptor::UrlString);
property->writeProperty(_qobject, &value, propertyWriteFlags);
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 864f97a417..adfa76ea24 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -1309,21 +1309,14 @@ bool QQmlPropertyPrivate::write(
return property.writeProperty(object, const_cast<QVariant *>(&value), flags);
} else if (isUrl) {
QUrl u;
- if (variantType == QMetaType::QUrl) {
+ if (variantType == QMetaType::QUrl)
u = value.toUrl();
- } else if (variantType == QMetaType::QByteArray) {
- QString input(QString::fromUtf8(value.toByteArray()));
- // Encoded dir-separators defeat QUrl processing - decode them first
- input.replace(QLatin1String("%2f"), QLatin1String("/"), Qt::CaseInsensitive);
- u = QUrl(input);
- } else if (variantType == QMetaType::QString) {
- QString input(value.toString());
- // Encoded dir-separators defeat QUrl processing - decode them first
- input.replace(QLatin1String("%2f"), QLatin1String("/"), Qt::CaseInsensitive);
- u = QUrl(input);
- } else {
+ else if (variantType == QMetaType::QByteArray)
+ u = QUrl(QString::fromUtf8(value.toByteArray()));
+ else if (variantType == QMetaType::QString)
+ u = QUrl(value.toString());
+ else
return false;
- }
if (context && u.isRelative() && !u.isEmpty())
u = context->resolvedUrl(u);
diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
index 8a96fc52c5..26bfd731e6 100644
--- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
+++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
@@ -1716,12 +1716,11 @@ void tst_qqmlproperty::urlHandling_data()
<< QString("/main.qml")
<< QByteArray("http://www.example.com/main.qml?type=text/qml&comment=now%20working?");
- // Although 'text%2Fqml' is pre-encoded, it will be decoded to allow correct QUrl classification
QTest::newRow("preencodedQuery")
<< QByteArray("http://www.example.com/main.qml?type=text%2Fqml&comment=now working%3F")
<< QString("http")
<< QString("/main.qml")
- << QByteArray("http://www.example.com/main.qml?type=text/qml&comment=now%20working%3F");
+ << QByteArray("http://www.example.com/main.qml?type=text%2Fqml&comment=now%20working%3F");
QTest::newRow("encodableFragment")
<< QByteArray("http://www.example.com/main.qml?type=text/qml#start+30000|volume+50%")
diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
index 552393491d..a204be8d59 100644
--- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp
+++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
@@ -214,11 +214,16 @@ 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" << testFileUrl("subdir/Test.qml") << "";
- QTest::newRow("source with encoded subdir optimized binding") << "source" << "source: 'subdir' + '%2fTest.qml'\n" << testFileUrl("subdir/Test.qml") << "";
- QTest::newRow("source with encoded subdir binding") << "source" << "source: encodeURIComponent('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("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")
<< QString(testFileUrl("IDontExist.qml").toString() + ": No such file or directory");