From: Thiago Macieira Date: Fri, 30 Mar 2012 19:21:45 +0000 (-0300) Subject: Allow {} to remain decoded in URLs in the path and query X-Git-Tag: 071012110112~1235^2^2~58 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=997ac954abe8e4f7d9323f13a79989f277de8301;p=profile%2Fivi%2Fqtbase.git Allow {} to remain decoded in URLs in the path and query This allows things like http://example.com/{1234-5678}?id={abcd-ef01}. But do not allow it in other parts of the URL. I could allow it in the fragment, but in the username and password it would be too ugly. In order to do that, make DecodeReserved use two bits and have PrettyDecoded set only one of them. That way, toString(PrettyDecoded) can be distinguished from toString(PrettyDecoded | DecodeReserved), just as path(PrettyDecoded) can be distinguished from path(PrettyDecoded & ~DecodeDelimiters). Also, take the opportunity to avoid decoding the reserved characters in the query. Keep them encoded as they should be. Change-Id: I1604a0c8015c6b03dc2fbf49ea9d1dbed96fc186 Reviewed-by: Shane Kearns --- diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 0821645..cbe39e9 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -382,7 +382,14 @@ static const ushort encodedPathActions[] = { leave('/'), // 4 0 }; -static const ushort * const decodedPathInUrlActions = encodedPathActions + 2; +static const ushort decodedPathInUrlActions[] = { + decode('{'), // 0 + decode('}'), // 1 + encode('?'), // 2 + encode('#'), // 3 + leave('/'), // 4 + 0 +}; static const ushort * const decodedPathInIsolationActions = encodedPathActions + 4; // leave('/') static const ushort encodedFragmentActions[] = { @@ -425,12 +432,6 @@ static const ushort decodedQueryInIsolationActions[] = { 0 }; static const ushort decodedQueryInUrlActions[] = { - decode('"'), // 0 - decode('<'), // 1 - decode('>'), // 2 - decode('^'), // 3 - decode('\\'),// 4 - decode('|'), // 5 decode('{'), // 6 decode('}'), // 7 encode('#'), // 8 @@ -2054,6 +2055,8 @@ QString QUrl::toString(FormattingOptions options) const } QString url; + if (!options.testFlag(DecodeReserved)) + options &= ~DecodeReserved; if (!(options & QUrl::RemoveScheme) && d->hasScheme()) url += d->scheme + QLatin1Char(':'); diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index 27b81df..ff46a8a 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -142,9 +142,10 @@ public: DecodeSpaces = 0x100000, DecodeUnicode = 0x200000, DecodeDelimiters = 0x400000 | 0x800000, - DecodeReserved = 0x1000000, + PrettyDecodeReserved = 0x1000000, + DecodeReserved = PrettyDecodeReserved | 0x2000000, - PrettyDecoded = DecodeSpaces | DecodeDelimiters | DecodeReserved | DecodeUnicode, + PrettyDecoded = DecodeSpaces | DecodeDelimiters | PrettyDecodeReserved | DecodeUnicode, MostDecoded = PrettyDecoded }; Q_DECLARE_FLAGS(ComponentFormattingOptions, ComponentFormattingOption) diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 7deb0fc..f8a0edf 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -2765,6 +2765,16 @@ void tst_QUrl::componentEncodings_data() << "host" << "%5B%3A%40/%5D:%5B:%40/%5D@host" << "/:@[?#]" << "[?%3F#]%5B:%3A@%40%5D" << "#" << "x://%5B%3A%40%2F%5D:%5B:%40%2F%5D@host/:@[%3F%23]?[?%3F%23]%5B:%3A@%40%5D##"; + + // the pretty form keeps the other characters decoded everywhere + // except when rebuilding the full URL, when we only allow "{}" to remain decoded + QTest::newRow("pretty-reserved") << QUrl("x://\"<>^\\{|}:\"<>^\\{|}@host/\"<>^\\{|}?\"<>^\\{|}#\"<>^\\{|}") + << int(QUrl::PrettyDecoded) + << "\"<>^\\{|}" << "\"<>^\\{|}" << "\"<>^\\{|}:\"<>^\\{|}" + << "host" << "\"<>^\\{|}:\"<>^\\{|}@host" + << "/\"<>^\\{|}" << "\"<>^\\{|}" << "\"<>^\\{|}" + << "x://%22%3C%3E%5E%5C%7B%7C%7D:%22%3C%3E%5E%5C%7B%7C%7D@host/%22%3C%3E%5E%5C{%7C}" + "?%22%3C%3E%5E%5C{%7C}#%22%3C%3E%5E%5C%7B%7C%7D"; } void tst_QUrl::componentEncodings()