diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-07-31 15:19:30 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-01 13:04:21 +0200 |
commit | 0838ac541d38b33b23955c036bbcfd94ccc19066 (patch) | |
tree | 8aec778ef4bc36a75247a84f3ee9ba498a13e875 /src/corelib | |
parent | e1038794b1d7fe298535960eb90d5c823aa3f2c4 (diff) |
Make sure that the parsing mode reaches QUrlPrivate::setHost
Ensure that the parsing mode is cascaded down from setAuthority and
setUrl so that the hostname parsing does not attempt to decode
percent-encoded hostnames when it shouldn't.
Take the opportunity to also remove the "Boolean Trap" from
QUrlPrivate::setHost.
Change-Id: Ia64754c4a4900182700b7af1382aea8410abc7e9
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qurl.cpp | 18 | ||||
-rw-r--r-- | src/corelib/io/qurl_p.h | 4 |
2 files changed, 11 insertions, 11 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index bc92e943fc..8cabc061fe 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -708,7 +708,7 @@ bool QUrlPrivate::setScheme(const QString &value, int len) return true; } -bool QUrlPrivate::setAuthority(const QString &auth, int from, int end) +bool QUrlPrivate::setAuthority(const QString &auth, int from, int end, QUrl::ParsingMode mode) { sectionHasError &= ~Authority; sectionIsPresent &= ~Authority; @@ -768,7 +768,7 @@ bool QUrlPrivate::setAuthority(const QString &auth, int from, int end) port = -1; } - return setHost(auth, from, qMin<uint>(end, colonIndex)) && !(sectionHasError & Port); + return setHost(auth, from, qMin<uint>(end, colonIndex), mode) && !(sectionHasError & Port); } void QUrlPrivate::setUserInfo(const QString &userInfo, int from, int end) @@ -955,7 +955,7 @@ static bool parseIp6(QString &host, const QChar *begin, const QChar *end) return true; } -bool QUrlPrivate::setHost(const QString &value, int from, int iend, bool maybePercentEncoded) +bool QUrlPrivate::setHost(const QString &value, int from, int iend, QUrl::ParsingMode mode) { const QChar *begin = value.constData() + from; const QChar *end = value.constData() + iend; @@ -1020,7 +1020,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::DecodeReserved, 0)) { + if (mode == QUrl::TolerantMode && qt_urlRecode(s, begin, end, QUrl::DecodeReserved, 0)) { // something was decoded // anything encoded left? if (s.contains(QChar(0x25))) { // '%' @@ -1030,7 +1030,7 @@ bool QUrlPrivate::setHost(const QString &value, int from, int iend, bool maybePe } // recurse - return setHost(s, 0, s.length(), false); + return setHost(s, 0, s.length(), QUrl::StrictMode); } s = qt_ACE_do(QString::fromRawData(begin, len), NormalizeAce); @@ -1111,7 +1111,7 @@ void QUrlPrivate::parse(const QString &url, QUrl::ParsingMode parsingMode) } } - setAuthority(url, hierStart + 2, authorityEnd); + setAuthority(url, hierStart + 2, authorityEnd, parsingMode); // even if we failed to set the authority properly, let's try to recover pathStart = authorityEnd; @@ -1649,7 +1649,7 @@ void QUrl::setAuthority(const QString &authority, ParsingMode mode) mode = TolerantMode; } - d->setAuthority(data, 0, data.length()); + d->setAuthority(data, 0, data.length(), mode); if (authority.isNull()) { // QUrlPrivate::setAuthority cleared almost everything // but it leaves the Host bit set @@ -1893,7 +1893,7 @@ void QUrl::setHost(const QString &host, ParsingMode mode) mode = TolerantMode; } - if (d->setHost(data, 0, data.length())) { + if (d->setHost(data, 0, data.length(), mode)) { if (host.isNull()) d->sectionIsPresent &= ~QUrlPrivate::Host; } else if (!data.startsWith(QLatin1Char('['))) { @@ -1902,7 +1902,7 @@ void QUrl::setHost(const QString &host, ParsingMode mode) ushort oldSupplement = d->errorSupplement; data.prepend(QLatin1Char('[')); data.append(QLatin1Char(']')); - if (!d->setHost(data, 0, data.length())) { + if (!d->setHost(data, 0, data.length(), mode)) { // failed again: choose if this was an IPv6 error or not if (!data.contains(QLatin1Char(':'))) { d->errorCode = oldCode; diff --git a/src/corelib/io/qurl_p.h b/src/corelib/io/qurl_p.h index 95ccd221a2..a1efb29ff8 100644 --- a/src/corelib/io/qurl_p.h +++ b/src/corelib/io/qurl_p.h @@ -123,11 +123,11 @@ public: // the "end" parameters are like STL iterators: they point to one past the last valid element bool setScheme(const QString &value, int len); - bool setAuthority(const QString &auth, int from, int end); + bool setAuthority(const QString &auth, int from, int end, QUrl::ParsingMode mode); void setUserInfo(const QString &userInfo, int from, int end); void setUserName(const QString &value, int from, int end); void setPassword(const QString &value, int from, int end); - bool setHost(const QString &value, int from, int end, bool maybePercentEncoded = true); + bool setHost(const QString &value, int from, int end, QUrl::ParsingMode mode); void setPath(const QString &value, int from, int end); void setQuery(const QString &value, int from, int end); void setFragment(const QString &value, int from, int end); |