diff --git a/src/corelib/io/qurlrecode.cpp b/src/corelib/io/qurlrecode.cpp index f4261f8f94c..f22df7a5afd 100644 --- a/src/corelib/io/qurlrecode.cpp +++ b/src/corelib/io/qurlrecode.cpp @@ -669,6 +669,9 @@ qsizetype qt_encodeFromUser(QString &appendTo, const QString &in, const ushort * actionTable['[' - ' '] = EncodeCharacter; actionTable[']' - ' '] = EncodeCharacter; + // Apply !EncodeSpaces, same as qt_urlRecode() above + actionTable[0] = DecodeCharacter; + if (tableModifications) { for (const ushort *p = tableModifications; *p; ++p) actionTable[uchar(*p) - ' '] = *p >> 8; diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index beb7698fa4a..ba56edc5d54 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -334,6 +334,25 @@ void tst_QUrl::comparison() QCOMPARE(url4EncodedDots.toString(), QString("example://a/.//b/..%2F/b/c/")); QCOMPARE(url4EncodedDots.adjusted(QUrl::NormalizePathSegments).toString(), QString("example://a//b/..%2F/b/c/")); + QUrl urlPathSetDecoded = QUrl("ws://localhost:12345/segment/with spaces/<é>", QUrl::TolerantMode); + QUrl urlPathSetEncoded = QUrl("ws://localhost:12345/segment/with%20spaces/%3C%c3%a9%3E", QUrl::TolerantMode); + QCOMPARE(urlPathSetDecoded, urlPathSetEncoded); + QUrl urlSetPathEncodedWithPercent = QUrl("ws://localhost:12345"); + urlSetPathEncodedWithPercent.setPath("/segment/with%20spaces/%3C%c3%a9%3E", QUrl::TolerantMode); + QUrl urlSetPathEncodedWithLiterals = QUrl("ws://localhost:12345"); + urlSetPathEncodedWithLiterals.setPath("/segment/with spaces/<é>", QUrl::TolerantMode); + QUrl urlSetPathDecoded = QUrl("ws://localhost:12345"); + urlSetPathDecoded.setPath("/segment/with spaces/<é>", QUrl::DecodedMode); + QCOMPARE(urlSetPathEncodedWithPercent, urlPathSetEncoded); + QCOMPARE(urlSetPathEncodedWithPercent, urlPathSetDecoded); + QCOMPARE(urlSetPathEncodedWithLiterals, urlPathSetEncoded); + QCOMPARE(urlSetPathEncodedWithLiterals, urlPathSetDecoded); + QCOMPARE(urlSetPathEncodedWithLiterals, urlSetPathEncodedWithPercent); + QCOMPARE(urlSetPathDecoded, urlPathSetEncoded); + QCOMPARE(urlSetPathDecoded, urlPathSetDecoded); + QCOMPARE(urlSetPathDecoded, urlSetPathEncodedWithPercent); + QCOMPARE(urlSetPathDecoded, urlSetPathEncodedWithLiterals); + // 6.2.2.1 Make sure hexdecimal characters in percent encoding are // treated case-insensitively QUrl url5;