summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qurlquery.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-03-29 22:59:56 -0300
committerQt by Nokia <qt-info@nokia.com>2012-04-11 23:31:46 +0200
commitef288340da61a72ac6d7ecb48e5bce5fef8cf11b (patch)
treebf804ed92b3a939c6a329636a9d92284d69b9e37 /src/corelib/io/qurlquery.cpp
parent8d3cb11261fe9d6ec2e071c959b836f7bfadc33d (diff)
Fix the handling of ambiguous delimiters in the query part of a URL
This is the same fix as the previous commit did for the other components of the URL. But we're also changing how we handle the "[]" characters in a query: previously the handling was like for other sub-delims; now, they're always decoded, assuming that the RFC had a mistake and they were meant to be decoded. Change-Id: If4b1c3df8f341cb114f2cc4860de22f8bf0be743 Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Diffstat (limited to 'src/corelib/io/qurlquery.cpp')
-rw-r--r--src/corelib/io/qurlquery.cpp29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/corelib/io/qurlquery.cpp b/src/corelib/io/qurlquery.cpp
index a24e73332c..85180a2d72 100644
--- a/src/corelib/io/qurlquery.cpp
+++ b/src/corelib/io/qurlquery.cpp
@@ -180,7 +180,8 @@ template<> void QSharedDataPointer<QUrlQueryPrivate>::detach()
// The strict definition of query says that it can have unencoded any
// unreserved, sub-delim, ":", "@", "/" and "?". Or, by exclusion, excluded
// delimiters are "#", "[" and "]" -- if those are present, they must be
-// percent-encoded.
+// percent-encoded. The fact that "[" and "]" should be encoded is probably a
+// mistake in the spec, so we ignore it and leave the decoded.
//
// The internal storage in the Map is equivalent to PrettyDecoded. That means
// the getter methods, when called with the default encoding value, will not
@@ -194,8 +195,8 @@ template<> void QSharedDataPointer<QUrlQueryPrivate>::detach()
// themselves.
//
// But when recreating the query string, in toString(), we must take care of
-// the special delimiters: the pair and value delimiters and those that the
-// definition says must be encoded ("#" / "[" / "]")
+// the special delimiters: the pair and value delimiters, as well as the "#"
+// character if unambiguous decoding is requested.
#define decode(x) ushort(x)
#define leave(x) ushort(0x100 | (x))
@@ -236,10 +237,9 @@ inline QString QUrlQueryPrivate::recodeToUser(const QString &input, QUrl::Compon
return input;
}
- // re-encode the gen-delims that the RFC says must be encoded the
- // query delimiter pair; the non-delimiters will get encoded too
+ // re-encode the "#" character and the query delimiter pair
ushort actions[] = { encode(pairDelimiter.unicode()), encode(valueDelimiter.unicode()),
- encode('#'), encode('['), encode(']'), 0 };
+ encode('#'), 0 };
QString output;
if (qt_urlRecode(output, input.constData(), input.constData() + input.length(), encoding, actions))
return output;
@@ -455,33 +455,26 @@ QString QUrlQuery::query(QUrl::ComponentFormattingOptions encoding) const
// unlike the component encoding, for the whole query we need to modify a little:
// - the "#" character is ambiguous, so we decode it only in DecodeAllDelimiters mode
// - the query delimiter pair must always be encoded
- // - the "[" and "]" sub-delimiters and the non-delimiters very on DecodeUnambiguousDelimiters
+ // - the non-delimiters vary on DecodeUnambiguousDelimiters
// so:
// - full encoding: encode the non-delimiters, the pair, "#", "[" and "]"
// - pretty decode: decode the non-delimiters, "[" and "]"; encode the pair and "#"
// - decode all: decode the non-delimiters, "[", "]", "#"; encode the pair
// start with what's always encoded
- ushort tableActions[7] = {
+ ushort tableActions[] = {
leave('+'), // 0
encode(d->pairDelimiter.unicode()), // 1
encode(d->valueDelimiter.unicode()), // 2
+ decode('#'), // 3
+ 0
};
- if ((encoding & QUrl::DecodeAllDelimiters) == QUrl::DecodeAllDelimiters) {
+ if (encoding & QUrl::DecodeAllDelimiters) {
// full decoding: we only encode the characters above
tableActions[3] = 0;
encoding |= QUrl::DecodeAllDelimiters;
} else {
tableActions[3] = encode('#');
- if (encoding & QUrl::DecodeUnambiguousDelimiters) {
- tableActions[4] = 0;
- encoding |= QUrl::DecodeAllDelimiters;
- } else {
- tableActions[4] = encode('[');
- tableActions[5] = encode(']');
- tableActions[6] = 0;
- encoding &= ~QUrl::DecodeAllDelimiters;
- }
}
QString result;