Port away from QUrl::MostDecoded
authorThiago Macieira <thiago.macieira@intel.com>
Mon, 21 May 2012 16:44:31 +0000 (18:44 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 22 May 2012 18:56:38 +0000 (20:56 +0200)
Since we're about to introduce QUrl::FullyDecoded, this
QUrl::MostDecoded value would be confusing. Replace its uses with what
was intended at the point in question.

Change-Id: Iefd87bc33d37bace507c5cb0f206fa902e08e2df
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: David Faure <faure@kde.org>
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
src/corelib/io/qurl.cpp
src/corelib/io/qurlquery.cpp
tests/auto/corelib/io/qurl/tst_qurl.cpp
tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp
tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp

index de67571..319de07 100644 (file)
@@ -505,7 +505,7 @@ recodeFromUser(const QString &input, const ushort *actions, int from, int to)
     const QChar *begin = input.constData() + from;
     const QChar *end = input.constData() + to;
     if (qt_urlRecode(output, begin, end,
-                     QUrl::MostDecoded, actions))
+                     QUrl::DecodeReserved, actions))
         return output;
 
     return input.mid(from, to - from);
@@ -1021,7 +1021,7 @@ bool QUrlPrivate::setHost(const QString &value, int from, int iend, bool maybePe
 
     // check for percent-encoding first
     QString s;
-    if (maybePercentEncoded && qt_urlRecode(s, begin, end, QUrl::MostDecoded, 0)) {
+    if (maybePercentEncoded && qt_urlRecode(s, begin, end, QUrl::DecodeReserved, 0)) {
         // something was decoded
         // anything encoded left?
         if (s.contains(QChar(0x25))) { // '%'
index 5625aeb..f5ba15a 100644 (file)
@@ -210,7 +210,7 @@ inline QString QUrlQueryPrivate::recodeFromUser(const QString &input) const
     // note: duplicated in setQuery()
     QString output;
     if (qt_urlRecode(output, input.constData(), input.constData() + input.length(),
-                     QUrl::MostDecoded,
+                     QUrl::DecodeReserved,
                      prettyDecodedActions))
         return output;
     return input;
@@ -269,7 +269,7 @@ void QUrlQueryPrivate::setQuery(const QString &query)
 
         QString key;
         if (!qt_urlRecode(key, begin, delimiter,
-                          QUrl::MostDecoded,
+                          QUrl::DecodeReserved,
                           prettyDecodedActions))
             key = QString(begin, delimiter - begin);
 
@@ -282,7 +282,7 @@ void QUrlQueryPrivate::setQuery(const QString &query)
         } else {
             QString value;
             if (!qt_urlRecode(value, delimiter + 1, pos,
-                              QUrl::MostDecoded,
+                              QUrl::DecodeReserved,
                               prettyDecodedActions))
                 value = QString(delimiter + 1, pos - delimiter - 1);
             itemList.append(qMakePair(key, value));
index 1f3dcae..45f2471 100644 (file)
@@ -1102,7 +1102,7 @@ void tst_QUrl::fromLocalFile()
 
     QUrl url = QUrl::fromLocalFile(theFile);
 
-    QCOMPARE(url.toString(QUrl::MostDecoded), theUrl);
+    QCOMPARE(url.toString(QUrl::DecodeReserved), theUrl);
     QCOMPARE(url.path(), thePath);
 }
 
@@ -2696,6 +2696,8 @@ void tst_QUrl::componentEncodings_data()
     QTest::addColumn<QString>("fragment");
     QTest::addColumn<QString>("toString");
 
+    const int MostDecoded = QUrl::DecodeReserved; // the most decoded mode without being fully decoded
+
     QTest::newRow("empty") << QUrl() << int(QUrl::FullyEncoded)
                            << QString() << QString() << QString()
                            << QString() << QString()
@@ -2710,7 +2712,7 @@ void tst_QUrl::componentEncodings_data()
                                    << "x://user%20name:pass%20word@host/path%20name?query%20value#fragment%20value";
 
     QTest::newRow("decoded-space") << QUrl("x://user%20name:pass%20word@host/path%20name?query%20value#fragment%20value")
-                                   << int(QUrl::MostDecoded)
+                                   << MostDecoded
                                    << "user name" << "pass word" << "user name:pass word"
                                    << "host" << "user name:pass word@host"
                                    << "/path name" << "query value" << "fragment value"
@@ -2719,7 +2721,7 @@ void tst_QUrl::componentEncodings_data()
     // binary data is always encoded
     // this is also testing non-UTF8 data
     QTest::newRow("binary") << QUrl("x://%c0%00:%c1%01@host/%c2%02?%c3%03#%d4%04")
-                            << int(QUrl::MostDecoded)
+                            << MostDecoded
                             << "%C0%00" << "%C1%01" << "%C0%00:%C1%01"
                             << "host" << "%C0%00:%C1%01@host"
                             << "/%C2%02" << "%C3%03" << "%D4%04"
@@ -2734,7 +2736,7 @@ void tst_QUrl::componentEncodings_data()
                                      << "/%E0%A0%80" << "%F0%90%80%80" << "%C3%A9"
                                      << "x://%C2%80:%C3%90@xn--smrbrd-cyad.example.no/%E0%A0%80?%F0%90%80%80#%C3%A9";
     QTest::newRow("decoded-unicode") << QUrl("x://%C2%80:%C3%90@XN--SMRBRD-cyad.example.NO/%E0%A0%80?%F0%90%80%80#%C3%A9")
-                                     << int(QUrl::MostDecoded)
+                                     << MostDecoded
                                      << QString::fromUtf8("\xc2\x80") << QString::fromUtf8("\xc3\x90")
                                      << QString::fromUtf8("\xc2\x80:\xc3\x90")
                                      << QString::fromUtf8("smørbrød.example.no")
@@ -2770,7 +2772,7 @@ void tst_QUrl::componentEncodings_data()
     // 1) test the delimiters that must appear encoded
     //    (if they were decoded, they'd would change the URL parsing)
     QTest::newRow("encoded-gendelims-changing") << QUrl("x://%5b%3a%2f%3f%23%40%5d:%5b%2f%3f%23%40%5d@host/%2f%3f%23?%23")
-                                                << int(QUrl::MostDecoded)
+                                                << MostDecoded
                                                 << "[:/?#@]" << "[/?#@]" << "[%3A/?#@]:[/?#@]"
                                                 << "host" << "%5B%3A/?#%40%5D:%5B/?#%40%5D@host"
                                                 << "/%2F?#" << "#" << ""
@@ -2797,7 +2799,7 @@ void tst_QUrl::componentEncodings_data()
 
     // 4) like above, but now decode them, which is allowed
     QTest::newRow("decoded-square-brackets") << QUrl("x:/%5B%5D#%5B%5D")
-                                             << int(QUrl::MostDecoded)
+                                             << MostDecoded
                                              << "" << "" << ""
                                              << "" << ""
                                              << "/[]" << "" << "[]"
@@ -2814,7 +2816,7 @@ void tst_QUrl::componentEncodings_data()
                                             << QString() << "!$()*+,;=:/?[]@%21%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D" << QString()
                                             << "?!$()*+,;=:/?[]@%21%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D";
     QTest::newRow("undecoded-delims-query") << QUrl("?!$()*+,;=:/?[]@%21%24%26%27%28%29%2a%2b%2c%2f%3a%3b%3d%3f%40%5b%5d")
-                                            << int(QUrl::MostDecoded)
+                                            << MostDecoded
                                             << QString() << QString() << QString()
                                             << QString() << QString()
                                             << QString() << "!$()*+,;=:/?[]@%21%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D" << QString()
index 43266f1..68aaa19 100644 (file)
@@ -822,7 +822,9 @@ static void addUtf8Data(const char *name, const char *data)
     QString encoded = QByteArray(data).toPercentEncoding();
     QString decoded = QString::fromUtf8(data);
 
-    QTest::newRow(QByteArray("decode-") + name) << encoded << QUrl::ComponentFormattingOptions(QUrl::MostDecoded) << decoded;
+    // this data contains invaild UTF-8 sequences, so FullyDecoded doesn't work (by design)
+    // use PrettyDecoded instead
+    QTest::newRow(QByteArray("decode-") + name) << encoded << QUrl::ComponentFormattingOptions(QUrl::PrettyDecoded) << decoded;
     QTest::newRow(QByteArray("encode-") + name) << decoded << QUrl::ComponentFormattingOptions(QUrl::FullyEncoded) << encoded;
 }
 
@@ -898,21 +900,21 @@ void tst_QUrlInternal::encodingRecode_data()
     }
 
     // encode control characters
-    QTest::newRow("encode-control") << "\1abc\2\033esc" << F(QUrl::MostDecoded) << "%01abc%02%1Besc";
-    QTest::newRow("encode-nul") << QString::fromLatin1("abc\0def", 7) << F(QUrl::MostDecoded) << "abc%00def";
+    QTest::newRow("encode-control") << "\1abc\2\033esc" << F(QUrl::PrettyDecoded) << "%01abc%02%1Besc";
+    QTest::newRow("encode-nul") << QString::fromLatin1("abc\0def", 7) << F(QUrl::PrettyDecoded) << "abc%00def";
 
     // space
-    QTest::newRow("space-leave-decoded") << "Hello World " << F(QUrl::MostDecoded) << "Hello World ";
+    QTest::newRow("space-leave-decoded") << "Hello World " << F(QUrl::PrettyDecoded) << "Hello World ";
     QTest::newRow("space-leave-encoded") << "Hello%20World%20" << F(QUrl::FullyEncoded) << "Hello%20World%20";
     QTest::newRow("space-encode") << "Hello World " << F(QUrl::FullyEncoded) << "Hello%20World%20";
-    QTest::newRow("space-decode") << "Hello%20World%20" << F(QUrl::MostDecoded) << "Hello World ";
+    QTest::newRow("space-decode") << "Hello%20World%20" << F(QUrl::PrettyDecoded) << "Hello World ";
 
     // decode unreserved
     QTest::newRow("unreserved-decode") << "%66%6f%6f%42a%72" << F(QUrl::FullyEncoded) << "fooBar";
 
     // mix encoding with decoding
-    QTest::newRow("encode-control-decode-space") << "\1\2%200" << F(QUrl::MostDecoded) << "%01%02 0";
-    QTest::newRow("decode-space-encode-control") << "%20\1\2" << F(QUrl::MostDecoded) << " %01%02";
+    QTest::newRow("encode-control-decode-space") << "\1\2%200" << F(QUrl::PrettyDecoded) << "%01%02 0";
+    QTest::newRow("decode-space-encode-control") << "%20\1\2" << F(QUrl::PrettyDecoded) << " %01%02";
 
     // decode and encode valid UTF-8 data
     // invalid is tested in encodingRecodeInvalidUtf8
@@ -947,11 +949,11 @@ void tst_QUrlInternal::encodingRecode_data()
     QTest::newRow("ff") << "%ff" << F(QUrl::FullyEncoded) << "%FF";
 
     // decode UTF-8 mixed with non-UTF-8 and unreserved
-    QTest::newRow("utf8-mix-1") << "%80%C2%80" << F(QUrl::MostDecoded) << QString::fromUtf8("%80\xC2\x80");
-    QTest::newRow("utf8-mix-2") << "%C2%C2%80" << F(QUrl::MostDecoded) << QString::fromUtf8("%C2\xC2\x80");
-    QTest::newRow("utf8-mix-3") << "%E0%C2%80" << F(QUrl::MostDecoded) << QString::fromUtf8("%E0\xC2\x80");
-    QTest::newRow("utf8-mix-3") << "A%C2%80" << F(QUrl::MostDecoded) << QString::fromUtf8("A\xC2\x80");
-    QTest::newRow("utf8-mix-3") << "%C2%80A" << F(QUrl::MostDecoded) << QString::fromUtf8("\xC2\x80""A");
+    QTest::newRow("utf8-mix-1") << "%80%C2%80" << F(QUrl::PrettyDecoded) << QString::fromUtf8("%80\xC2\x80");
+    QTest::newRow("utf8-mix-2") << "%C2%C2%80" << F(QUrl::PrettyDecoded) << QString::fromUtf8("%C2\xC2\x80");
+    QTest::newRow("utf8-mix-3") << "%E0%C2%80" << F(QUrl::PrettyDecoded) << QString::fromUtf8("%E0\xC2\x80");
+    QTest::newRow("utf8-mix-3") << "A%C2%80" << F(QUrl::PrettyDecoded) << QString::fromUtf8("A\xC2\x80");
+    QTest::newRow("utf8-mix-3") << "%C2%80A" << F(QUrl::PrettyDecoded) << QString::fromUtf8("\xC2\x80""A");
 }
 
 void tst_QUrlInternal::encodingRecode()
@@ -993,7 +995,7 @@ void tst_QUrlInternal::encodingRecodeInvalidUtf8()
     // prepend some data to be sure that it remains there
     QString output = QTest::currentDataTag();
 
-    if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), QUrl::MostDecoded))
+    if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), QUrl::PrettyDecoded))
         output += input;
     QCOMPARE(output, QTest::currentDataTag() + input);
 
index 7148a71..c8766f1 100644 (file)
@@ -626,7 +626,7 @@ void tst_QUrlQuery::encodedSetQueryItems_data()
     // plus signs must not be touched
     QTest::newRow("encode-plus") << "+=+" << "+" << "+" << F(QUrl::FullyEncoded)
                             << "+=+" << "+" << "+";
-    QTest::newRow("decode-2b") << "%2b=%2b" << "%2b" << "%2b" << F(QUrl::MostDecoded)
+    QTest::newRow("decode-2b") << "%2b=%2b" << "%2b" << "%2b" << F(QUrl::PrettyDecoded)
                             << "%2B=%2B" << "%2B" << "%2B";
 
 
@@ -683,7 +683,7 @@ void tst_QUrlQuery::differentDelimiters()
         expected << qItem("foo", "bar") << qItem("hello", "world");
         COMPARE_ITEMS(query.queryItems(), expected);
         COMPARE_ITEMS(query.queryItems(QUrl::FullyEncoded), expected);
-        COMPARE_ITEMS(query.queryItems(QUrl::MostDecoded), expected);
+        COMPARE_ITEMS(query.queryItems(QUrl::PrettyDecoded), expected);
     }
 
     {