diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-03-30 17:48:42 -0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-11 23:32:26 +0200 |
commit | 1b7e9dba75f18342911bc6954be3e754322f091f (patch) | |
tree | 1dfb775910294ff8d02e60cfa9c2bf178baa6221 /tests | |
parent | 997ac954abe8e4f7d9323f13a79989f277de8301 (diff) |
Change the component formatting enum values so the default is zero
By having the default value equal to zero, we follow the principle of
least surprise. For example, if we had
url.path()
and we refactored to
url.path(QUrl::DecodeSpaces)
Then instead of ensuring spaces are decoded, we make spaces the only
thing encoded (unicode, delimiters and reserved characters are
encoded).
Besides, modifying the default can only be used to encode something
that wasn't encoded previously, so having the enums as Encode makes
more sense.
As a side-effect, toEncoded() does not support any extra encoding
options.
Change-Id: I2624ec446e65c2d979e9ca2f81bd3db22b00bb13
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 18 | ||||
-rw-r--r-- | tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp | 30 | ||||
-rw-r--r-- | tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp | 13 |
3 files changed, 33 insertions, 28 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index f8a0edf0dc..5611f5b2f4 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -2599,14 +2599,14 @@ void tst_QUrl::componentEncodings_data() // hostname cannot contain spaces QTest::newRow("encoded-space") << QUrl("x://user name:pass word@host/path name?query value#fragment value") - << int(QUrl::FullyEncoded) + << int(QUrl::EncodeSpaces) << "user%20name" << "pass%20word" << "user%20name:pass%20word" << "host" << "user%20name:pass%20word@host" << "/path%20name" << "query%20value" << "fragment%20value" << "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::DecodeSpaces) + << int(QUrl::MostDecoded) << "user name" << "pass word" << "user name:pass word" << "host" << "user name:pass word@host" << "/path name" << "query value" << "fragment value" @@ -2624,13 +2624,13 @@ void tst_QUrl::componentEncodings_data() // unicode tests // hostnames can participate in this test, but we need a top-level domain that accepts Unicode QTest::newRow("encoded-unicode") << QUrl(QString::fromUtf8("x://\xc2\x80:\xc3\x90@smørbrød.example.no/\xe0\xa0\x80?\xf0\x90\x80\x80#é")) - << int(QUrl::FullyEncoded) + << int(QUrl::EncodeUnicode) << "%C2%80" << "%C3%90" << "%C2%80:%C3%90" << "xn--smrbrd-cyad.example.no" << "%C2%80:%C3%90@xn--smrbrd-cyad.example.no" << "/%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::DecodeUnicode) + << int(QUrl::MostDecoded) << QString::fromUtf8("\xc2\x80") << QString::fromUtf8("\xc3\x90") << QString::fromUtf8("\xc2\x80:\xc3\x90") << QString::fromUtf8("smørbrød.example.no") @@ -2661,8 +2661,10 @@ void tst_QUrl::componentEncodings_data() // gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" // these are the separators between fields - // they must appear encoded in proper URLs everywhere - // 1) test the delimiters that, if they were decoded, would change the URL parsing + // they must appear encoded in certain positions, no exceptions + // in other positions, they can appear decoded, so they always do + // 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) << "[:/?#@]" << "[/?#@]" << "[%3A/?#@]:[/?#@]" @@ -2674,7 +2676,7 @@ void tst_QUrl::componentEncodings_data() // and test that %2f is *not* decoded to a slash in the path // don't test the query because in this mode it doesn't transform anything QTest::newRow("decoded-gendelims-unchanging") << QUrl("x://:%3a@host/%2f%3a%40#%23%3a%2f%3f%40") - << int(QUrl::DecodeDelimiters) + << int(QUrl::FullyEncoded) << "" << ":" << "::" << "host" << "::@host" << "/%2F:@" << "" << "#:/?@" @@ -2707,7 +2709,7 @@ void tst_QUrl::componentEncodings_data() << QString() << "!$()*+,;=:/?[]@" << QString() << "?!$()*+,;=:/?[]@"; 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::DecodeDelimiters) + << int(QUrl::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() diff --git a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp index f853bab9e5..3ac2b46964 100644 --- a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp +++ b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp @@ -812,7 +812,7 @@ void tst_QUrlInternal::correctEncodedMistakes() QString output = QTest::currentDataTag(); expected.prepend(output); - if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), QUrl::DecodeUnicode)) + if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), 0)) output += input; QCOMPARE(output, expected); } @@ -822,7 +822,7 @@ 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::DecodeUnicode) << decoded; + QTest::newRow(QByteArray("decode-") + name) << encoded << QUrl::ComponentFormattingOptions(QUrl::MostDecoded) << decoded; QTest::newRow(QByteArray("encode-") + name) << decoded << QUrl::ComponentFormattingOptions(QUrl::FullyEncoded) << encoded; } @@ -877,17 +877,17 @@ void tst_QUrlInternal::encodingRecode_data() QTest::newRow("encode-nul") << QString::fromLatin1("abc\0def", 7) << F(QUrl::MostDecoded) << "abc%00def"; // space - QTest::newRow("space-leave-decoded") << "Hello World " << F(QUrl::DecodeSpaces) << "Hello World "; + QTest::newRow("space-leave-decoded") << "Hello World " << F(QUrl::MostDecoded) << "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::DecodeSpaces) << "Hello World "; + QTest::newRow("space-decode") << "Hello%20World%20" << F(QUrl::MostDecoded) << "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::DecodeSpaces) << "%01%02 0"; - QTest::newRow("decode-space-encode-control") << "%20\1\2" << F(QUrl::DecodeSpaces) << " %01%02"; + 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"; // decode and encode valid UTF-8 data // invalid is tested in encodingRecodeInvalidUtf8 @@ -922,11 +922,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::DecodeUnicode) << QString::fromUtf8("%80\xC2\x80"); - QTest::newRow("utf8-mix-2") << "%C2%C2%80" << F(QUrl::DecodeUnicode) << QString::fromUtf8("%C2\xC2\x80"); - QTest::newRow("utf8-mix-3") << "%E0%C2%80" << F(QUrl::DecodeUnicode) << QString::fromUtf8("%E0\xC2\x80"); - QTest::newRow("utf8-mix-3") << "A%C2%80" << F(QUrl::DecodeUnicode) << QString::fromUtf8("A\xC2\x80"); - QTest::newRow("utf8-mix-3") << "%C2%80A" << F(QUrl::DecodeUnicode) << QString::fromUtf8("\xC2\x80""A"); + 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"); } void tst_QUrlInternal::encodingRecode() @@ -955,9 +955,9 @@ void tst_QUrlInternal::encodingRecodeInvalidUtf8_data() extern void loadNonCharactersRows(); loadNonCharactersRows(); - QTest::newRow("utf8-mix-4") << QByteArray("\xE0!A2\x80"); - QTest::newRow("utf8-mix-5") << QByteArray("\xE0\xA2!80"); - QTest::newRow("utf8-mix-5") << QByteArray("\xE0\xA2\x33"); + QTest::newRow("utf8-mix-4") << QByteArray("\xE0.A2\x80"); + QTest::newRow("utf8-mix-5") << QByteArray("\xE0\xA2.80"); + QTest::newRow("utf8-mix-6") << QByteArray("\xE0\xA2\x33"); } void tst_QUrlInternal::encodingRecodeInvalidUtf8() @@ -968,7 +968,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::DecodeUnicode)) + if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), QUrl::MostDecoded)) output += input; QCOMPARE(output, QTest::currentDataTag() + input); diff --git a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp index 24b651a8a3..7148a71153 100644 --- a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp +++ b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp @@ -593,10 +593,13 @@ void tst_QUrlQuery::encodedSetQueryItems_data() QTest::newRow("encode-space") << " = " << " " << " " << F(QUrl::FullyEncoded) << "%20=%20" << "%20" << "%20"; - QTest::newRow("non-delimiters") << "%3C%5C%3E=%7B%7C%7D%5E%60" << "%3C%5C%3E" << "%7B%7C%7D%5E%60" << F(QUrl::PrettyDecoded) + // tri-state + QTest::newRow("decode-non-delimiters") << "%3C%5C%3E=%7B%7C%7D%5E%60" << "%3C%5C%3E" << "%7B%7C%7D%5E%60" << F(QUrl::DecodeReserved) << "<\\>={|}^`" << "<\\>" << "{|}^`"; - QTest::newRow("encode-non-delimiters") << "<\\>={|}^`" << "<\\>" << "{|}^`" << F(QUrl::FullyEncoded) + QTest::newRow("encode-non-delimiters") << "<\\>={|}^`" << "<\\>" << "{|}^`" << F(QUrl::EncodeReserved) << "%3C%5C%3E=%7B%7C%7D%5E%60" << "%3C%5C%3E" << "%7B%7C%7D%5E%60"; + QTest::newRow("pretty-non-delimiters") << "<\\>={|}^`" << "<\\>" << "{|}^`" << F(QUrl::PrettyDecoded) + << "%3C%5C%3E=%7B%7C%7D%5E%60" << "<\\>" << "{|}^`"; QTest::newRow("equals") << "%3D=%3D" << "%3D" << "%3D" << F(QUrl::PrettyDecoded) << "%3D=%3D" << "=" << "="; @@ -606,7 +609,7 @@ void tst_QUrlQuery::encodedSetQueryItems_data() << "%26=%26" << "&" << "&"; QTest::newRow("hash") << "#=#" << "%23" << "%23" << F(QUrl::PrettyDecoded) << "#=#" << "#" << "#"; - QTest::newRow("decode-hash") << "%23=%23" << "%23" << "%23" << F(QUrl::DecodeDelimiters) + QTest::newRow("decode-hash") << "%23=%23" << "%23" << "%23" << F(QUrl::PrettyDecoded) << "#=#" << "#" << "#"; QTest::newRow("percent") << "%25=%25" << "%25" << "%25" << F(QUrl::PrettyDecoded) @@ -623,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::DecodeDelimiters) + QTest::newRow("decode-2b") << "%2b=%2b" << "%2b" << "%2b" << F(QUrl::MostDecoded) << "%2B=%2B" << "%2B" << "%2B"; @@ -680,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::DecodeDelimiters), expected); + COMPARE_ITEMS(query.queryItems(QUrl::MostDecoded), expected); } { |