diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2013-07-03 16:47:30 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-04 04:48:05 +0200 |
commit | 1fa5ea7a6a0719f4c52ac9ba3e61fc8ad0cd10bf (patch) | |
tree | 6f87d487aadbd93489803f932f7d5f9ddf1a1232 /src/corelib/io/qurl.cpp | |
parent | 6aa15690ffba0772ffeebf3d5199d94fa0d72bff (diff) |
Remove fully-decoded QUrl user info and authority sections
Those sections contain more than one components of a URL, separated by
delimiters. For that reason, QUrl::FullyDecoded and QUrl::DecodedMode do
not make sense, since they would cause the returned value to be
ambiguous and/or fail to parse again.
In fact, there was a comment in the test saying "look how it becomes
ambiguous".
Those modes are already forbidden in the setters and getters of the full
URL (setUrl(), url(), toString() and toEncoded()).
[ChangeLog][Important Behavior Changes][QUrl and QUrlQuery] QUrl no
longer supports QUrl::FullyDecoded mode in authority() and userInfo(),
nor QUrl::DecodedMode in setAuthority() and setUserInfo().
Change-Id: I538f7981a9f5a09f07d3879d31ccf6f0c8bfd940
Reviewed-by: David Faure (KDE) <faure@kde.org>
Diffstat (limited to 'src/corelib/io/qurl.cpp')
-rw-r--r-- | src/corelib/io/qurl.cpp | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index ac099591ba..10550a5b62 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -301,9 +301,6 @@ encoding sequence, including control characters (U+0000 to U+001F) and UTF-8 sequences found in percent-encoded form. Use of this mode may cause data loss, see below for more information. - This mode is should not be used in functions where more - than one URL component is returned (userInfo() and authority()) - and it is not allowed in url() and toString(). The values of EncodeReserved and DecodeReserved should not be used together in one call. The behavior is undefined if that happens. They are provided @@ -1885,10 +1882,11 @@ QString QUrl::scheme() const and some characters (including space) are not allowed in undecoded form. In TolerantMode (the default), all characters are accepted in undecoded form and the tolerant parser will correct stray '%' not followed by two hex - characters. In DecodedMode, '%' stand for themselves and encoded characters - are not possible. Because of that, in DecodedMode, it is not possible to - use the delimiter characters as non-delimiters (e.g., a password containing - a '@'). + characters. + + This function does not allow \a mode to be QUrl::DecodedMode. To set fully + decoded data, call setUserName(), setPassword(), setHost() and setPort() + individually. \sa setUserInfo(), setHost(), setPort() */ @@ -1896,13 +1894,13 @@ void QUrl::setAuthority(const QString &authority, ParsingMode mode) { detach(); d->clearError(); - QString data = authority; + if (mode == DecodedMode) { - parseDecodedComponent(data); - mode = TolerantMode; + qWarning("QUrl::setAuthority(): QUrl::DecodedMode is not permitted in this function"); + return; } - d->setAuthority(data, 0, data.length(), mode); + d->setAuthority(authority, 0, authority.length(), mode); if (authority.isNull()) { // QUrlPrivate::setAuthority cleared almost everything // but it leaves the Host bit set @@ -1914,13 +1912,14 @@ void QUrl::setAuthority(const QString &authority, ParsingMode mode) Returns the authority of the URL if it is defined; otherwise an empty string is returned. - The \a options argument controls how to format the authority portion of the - URL. The value of QUrl::FullyDecoded should be avoided, since it may - produce an ambiguous return value (for example, if the username contains a - colon ':' or either the username or password contain an at-sign '@'). In - all other cases, this function returns an unambiguous value, which may - contain those characters still percent-encoded, plus some control - sequences not representable in decoded form in QString. + This function returns an unambiguous value, which may contain that + characters still percent-encoded, plus some control sequences not + representable in decoded form in QString. + + The \a options argument controls how to format the user info component. The + value of QUrl::FullyDecoded is not permitted in this function. If you need + to obtain fully decoded data, call userName(), password(), host() and + port() individually. \sa setAuthority(), userInfo(), userName(), password(), host(), port() */ @@ -1928,6 +1927,11 @@ QString QUrl::authority(ComponentFormattingOptions options) const { if (!d) return QString(); + if (options == QUrl::FullyDecoded) { + qWarning("QUrl::authority(): QUrl::FullyDecoded is not permitted in this function"); + return QString(); + } + QString result; d->appendAuthority(result, options, QUrlPrivate::Authority); return result; @@ -1949,9 +1953,10 @@ QString QUrl::authority(ComponentFormattingOptions options) const and some characters (including space) are not allowed in undecoded form. In TolerantMode (the default), all characters are accepted in undecoded form and the tolerant parser will correct stray '%' not followed by two hex - characters. In DecodedMode, '%' stand for themselves and encoded characters - are not possible. Because of that, in DecodedMode, it is not possible to - use the ':' delimiter characters as non-delimiter in the user name. + characters. + + This function does not allow \a mode to be QUrl::DecodedMode. To set fully + decoded data, call setUserName() and setPassword() individually. \sa userInfo(), setUserName(), setPassword(), setAuthority() */ @@ -1961,8 +1966,8 @@ void QUrl::setUserInfo(const QString &userInfo, ParsingMode mode) d->clearError(); QString trimmed = userInfo.trimmed(); if (mode == DecodedMode) { - parseDecodedComponent(trimmed); - mode = TolerantMode; + qWarning("QUrl::setUserInfo(): QUrl::DecodedMode is not permitted in this function"); + return; } d->setUserInfo(trimmed, 0, trimmed.length()); @@ -1981,12 +1986,13 @@ void QUrl::setUserInfo(const QString &userInfo, ParsingMode mode) Returns the user info of the URL, or an empty string if the user info is undefined. + This function returns an unambiguous value, which may contain that + characters still percent-encoded, plus some control sequences not + representable in decoded form in QString. + The \a options argument controls how to format the user info component. The - value of QUrl::FullyDecoded should be avoided, since it may produce an - ambiguous return value (for example, if the username contains a colon ':'). - In all other cases, this function returns an unambiguous value, which may - contain that characters still percent-encoded, plus some control sequences - not representable in decoded form in QString. + value of QUrl::FullyDecoded is not permitted in this function. If you need + to obtain fully decoded data, call userName() and password() individually. \sa setUserInfo(), userName(), password(), authority() */ @@ -1994,6 +2000,11 @@ QString QUrl::userInfo(ComponentFormattingOptions options) const { if (!d) return QString(); + if (options == QUrl::FullyDecoded) { + qWarning("QUrl::userInfo(): QUrl::FullyDecoded is not permitted in this function"); + return QString(); + } + QString result; d->appendUserInfo(result, options, QUrlPrivate::UserInfo); return result; |