Merge QUrl::DecodeAllDelimiters and QUrl::DecodeUnambiguousDelimiters
There's little value in having the DecodeUnambiguousDelimiters option since neither QUrl nor QUrlQuery can return values that are ambiguous in that particular context, ever. This option could be used to encode a character if, when placed in a URL, it would need to be encoded. Such cases are hash (#) or question marks (?) in the path component, or slashes (/) and at signs (@) in the userinfo. However, we don't need two enums for that, since there are no other characters that can appear in either form. Still, leave two bits for this enum. In the future, if we want to split the gen-delims from the sub-delims, we are able to. Change-Id: If5416b524680eb67dd4abbe7d072ca0ef7218506 Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
This commit is contained in:
parent
9af551f7ab
commit
0441b2d4c3
@ -445,7 +445,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::DecodeUnicode | QUrl::DecodeAllDelimiters | QUrl::DecodeSpaces, actions))
|
||||
QUrl::MostDecoded, actions))
|
||||
return output;
|
||||
|
||||
return input.mid(from, to - from);
|
||||
@ -466,7 +466,7 @@ static inline void appendToUser(QString &appendTo, const QString &value, QUrl::F
|
||||
}
|
||||
|
||||
const ushort *actions = 0;
|
||||
if (options & QUrl::DecodeAllDelimiters)
|
||||
if (options & QUrl::DecodeDelimiters)
|
||||
actions = decodedActions;
|
||||
else
|
||||
actions = encodedActions;
|
||||
@ -494,7 +494,7 @@ void QUrlPrivate::appendUserInfo(QString &appendTo, QUrl::FormattingOptions opti
|
||||
|
||||
const ushort *userNameActions;
|
||||
const ushort *passwordActions;
|
||||
if (options & QUrl::DecodeAllDelimiters) {
|
||||
if (options & QUrl::DecodeDelimiters) {
|
||||
switch (appendingTo) {
|
||||
case UserInfo:
|
||||
userNameActions = decodedUserNameInUserInfoActions;
|
||||
@ -540,7 +540,7 @@ inline void QUrlPrivate::appendPassword(QString &appendTo, QUrl::FormattingOptio
|
||||
|
||||
inline void QUrlPrivate::appendPath(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
|
||||
{
|
||||
if (appendingTo != Path && options & QUrl::DecodeAllDelimiters) {
|
||||
if (appendingTo != Path && options & QUrl::DecodeDelimiters) {
|
||||
if (!qt_urlRecode(appendTo, path.constData(), path.constEnd(), options, decodedPathInUrlActions))
|
||||
appendTo += path;
|
||||
|
||||
@ -564,11 +564,11 @@ inline void QUrlPrivate::appendQuery(QString &appendTo, QUrl::FormattingOptions
|
||||
}
|
||||
|
||||
const ushort *actions = 0;
|
||||
if (options & QUrl::DecodeAllDelimiters) {
|
||||
if (options & QUrl::DecodeDelimiters) {
|
||||
// reset to default qt_urlRecode behaviour (leave delimiters alone)
|
||||
options &= ~QUrl::DecodeAllDelimiters;
|
||||
options &= ~QUrl::DecodeDelimiters;
|
||||
actions = appendingTo == Query ? decodedQueryInIsolationActions : decodedQueryInUrlActions;
|
||||
} else if ((options & QUrl::DecodeAllDelimiters) == 0) {
|
||||
} else if ((options & QUrl::DecodeDelimiters) == 0) {
|
||||
actions = encodedQueryActions;
|
||||
}
|
||||
|
||||
|
@ -140,12 +140,11 @@ public:
|
||||
enum ComponentFormattingOption {
|
||||
FullyEncoded = 0x000000,
|
||||
DecodeSpaces = 0x100000,
|
||||
DecodeUnambiguousDelimiters = 0x200000,
|
||||
DecodeAllDelimiters = DecodeUnambiguousDelimiters | 0x400000,
|
||||
DecodeDelimiters = 0x200000 | 0x400000,
|
||||
DecodeUnicode = 0x800000,
|
||||
|
||||
PrettyDecoded = DecodeSpaces | DecodeUnambiguousDelimiters | DecodeUnicode,
|
||||
MostDecoded = PrettyDecoded | DecodeAllDelimiters
|
||||
PrettyDecoded = DecodeSpaces | DecodeDelimiters | DecodeUnicode,
|
||||
MostDecoded = PrettyDecoded
|
||||
};
|
||||
Q_DECLARE_FLAGS(ComponentFormattingOptions, ComponentFormattingOption)
|
||||
#ifdef qdoc
|
||||
|
@ -208,7 +208,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::DecodeUnicode | QUrl::DecodeAllDelimiters | QUrl::DecodeSpaces,
|
||||
QUrl::MostDecoded,
|
||||
prettyDecodedActions))
|
||||
return output;
|
||||
return input;
|
||||
@ -216,7 +216,7 @@ inline QString QUrlQueryPrivate::recodeFromUser(const QString &input) const
|
||||
|
||||
inline bool idempotentRecodeToUser(QUrl::ComponentFormattingOptions encoding)
|
||||
{
|
||||
return encoding == QUrl::PrettyDecoded || encoding == (QUrl::PrettyDecoded | QUrl::DecodeAllDelimiters);
|
||||
return encoding == QUrl::PrettyDecoded;
|
||||
}
|
||||
|
||||
inline QString QUrlQueryPrivate::recodeToUser(const QString &input, QUrl::ComponentFormattingOptions encoding) const
|
||||
@ -226,13 +226,10 @@ inline QString QUrlQueryPrivate::recodeToUser(const QString &input, QUrl::Compon
|
||||
if (idempotentRecodeToUser(encoding))
|
||||
return input;
|
||||
|
||||
bool decodeUnambiguous = encoding & QUrl::DecodeUnambiguousDelimiters;
|
||||
encoding &= ~QUrl::DecodeAllDelimiters;
|
||||
|
||||
if (decodeUnambiguous) {
|
||||
if (encoding & QUrl::DecodeDelimiters) {
|
||||
QString output;
|
||||
if (qt_urlRecode(output, input.constData(), input.constData() + input.length(),
|
||||
encoding | QUrl::DecodeAllDelimiters, prettyDecodedActions))
|
||||
encoding, prettyDecodedActions))
|
||||
return output;
|
||||
return input;
|
||||
}
|
||||
@ -270,7 +267,7 @@ void QUrlQueryPrivate::setQuery(const QString &query)
|
||||
|
||||
QString key;
|
||||
if (!qt_urlRecode(key, begin, delimiter,
|
||||
QUrl::DecodeUnicode | QUrl::DecodeAllDelimiters | QUrl::DecodeSpaces,
|
||||
QUrl::MostDecoded,
|
||||
prettyDecodedActions))
|
||||
key = QString(begin, delimiter - begin);
|
||||
|
||||
@ -283,7 +280,7 @@ void QUrlQueryPrivate::setQuery(const QString &query)
|
||||
} else {
|
||||
QString value;
|
||||
if (!qt_urlRecode(value, delimiter + 1, pos,
|
||||
QUrl::DecodeUnicode | QUrl::DecodeAllDelimiters | QUrl::DecodeSpaces,
|
||||
QUrl::MostDecoded,
|
||||
prettyDecodedActions))
|
||||
value = QString(delimiter + 1, pos - delimiter - 1);
|
||||
itemList.append(qMakePair(key, value));
|
||||
@ -469,10 +466,9 @@ QString QUrlQuery::query(QUrl::ComponentFormattingOptions encoding) const
|
||||
decode('#'), // 3
|
||||
0
|
||||
};
|
||||
if (encoding & QUrl::DecodeAllDelimiters) {
|
||||
if (encoding & QUrl::DecodeDelimiters) {
|
||||
// full decoding: we only encode the characters above
|
||||
tableActions[3] = 0;
|
||||
encoding |= QUrl::DecodeAllDelimiters;
|
||||
} else {
|
||||
tableActions[3] = encode('#');
|
||||
}
|
||||
|
@ -469,7 +469,7 @@ qt_urlRecode(QString &appendTo, const QChar *begin, const QChar *end,
|
||||
QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications)
|
||||
{
|
||||
uchar actionTable[sizeof defaultActionTable];
|
||||
if (encoding & QUrl::DecodeAllDelimiters) {
|
||||
if (encoding & QUrl::DecodeDelimiters) {
|
||||
// reset the table
|
||||
memset(actionTable, DecodeCharacter, sizeof actionTable);
|
||||
if (!(encoding & QUrl::DecodeSpaces))
|
||||
|
@ -142,7 +142,7 @@ template<> inline char *toString(const QRectF &s)
|
||||
|
||||
template<> inline char *toString(const QUrl &uri)
|
||||
{
|
||||
return qstrdup(uri.toEncoded(QUrl::DecodeUnambiguousDelimiters).constData());
|
||||
return qstrdup(uri.toEncoded(QUrl::DecodeDelimiters).constData());
|
||||
}
|
||||
|
||||
template<> inline char *toString(const QVariant &v)
|
||||
|
@ -2674,7 +2674,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::DecodeUnambiguousDelimiters)
|
||||
<< int(QUrl::DecodeDelimiters)
|
||||
<< "" << ":" << "::"
|
||||
<< "host" << "::@host"
|
||||
<< "/%2F:@" << "" << "#:/?@"
|
||||
@ -2707,7 +2707,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::DecodeUnambiguousDelimiters)
|
||||
<< int(QUrl::DecodeDelimiters)
|
||||
<< QString() << QString() << QString()
|
||||
<< QString() << QString()
|
||||
<< QString() << "%21%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D" << QString()
|
||||
@ -2726,7 +2726,7 @@ void tst_QUrl::componentEncodings_data()
|
||||
"?%22%3C%3E%5E%5C%7B%7C%7D#%22%3C%3E%5E%5C%7B%7C%7D";
|
||||
QTest::newRow("decoded-others") << QUrl("x://%22%3C%3E%5E%5C%7B%7C%7D:%22%3C%3E%5E%5C%7B%7C%7D@host"
|
||||
"/%22%3C%3E%5E%5C%7B%7C%7D?%22%3C%3E%5E%5C%7B%7C%7D#%22%3C%3E%5E%5C%7B%7C%7D")
|
||||
<< int(QUrl::DecodeAllDelimiters)
|
||||
<< int(QUrl::DecodeDelimiters)
|
||||
<< "\"<>^\\{|}" << "\"<>^\\{|}" << "\"<>^\\{|}:\"<>^\\{|}"
|
||||
<< "host" << "\"<>^\\{|}:\"<>^\\{|}@host"
|
||||
<< "/\"<>^\\{|}" << "\"<>^\\{|}" << "\"<>^\\{|}"
|
||||
|
@ -605,8 +605,8 @@ void tst_QUrlQuery::encodedSetQueryItems_data()
|
||||
QTest::newRow("ampersand") << "%26=%26" << "%26" << "%26" << F(QUrl::PrettyDecoded)
|
||||
<< "%26=%26" << "&" << "&";
|
||||
QTest::newRow("hash") << "#=#" << "%23" << "%23" << F(QUrl::PrettyDecoded)
|
||||
<< "%23=%23" << "#" << "#";
|
||||
QTest::newRow("decode-hash") << "%23=%23" << "%23" << "%23" << F(QUrl::DecodeAllDelimiters)
|
||||
<< "#=#" << "#" << "#";
|
||||
QTest::newRow("decode-hash") << "%23=%23" << "%23" << "%23" << F(QUrl::DecodeDelimiters)
|
||||
<< "#=#" << "#" << "#";
|
||||
|
||||
QTest::newRow("percent") << "%25=%25" << "%25" << "%25" << F(QUrl::PrettyDecoded)
|
||||
@ -623,7 +623,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::DecodeAllDelimiters)
|
||||
QTest::newRow("decode-2b") << "%2b=%2b" << "%2b" << "%2b" << F(QUrl::DecodeDelimiters)
|
||||
<< "%2B=%2B" << "%2B" << "%2B";
|
||||
|
||||
|
||||
@ -680,7 +680,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::DecodeAllDelimiters), expected);
|
||||
COMPARE_ITEMS(query.queryItems(QUrl::DecodeDelimiters), expected);
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user