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>bb10
parent
6aa15690ff
commit
1fa5ea7a6a
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -3503,9 +3503,6 @@ void tst_QUrl::setComponents_data()
|
|||
QTest::newRow("invalid-scheme-encode") << QUrl("http://example.com")
|
||||
<< int(Scheme) << "http%61" << Decoded << false
|
||||
<< PrettyDecoded << "" << "";
|
||||
QTest::newRow("userinfo-encode") << QUrl("http://example.com")
|
||||
<< int(UserInfo) << "h%61llo:world@" << Decoded << true
|
||||
<< PrettyDecoded << "h%2561llo:world@" << "http://h%2561llo:world%40@example.com";
|
||||
QTest::newRow("username-encode") << QUrl("http://example.com")
|
||||
<< int(UserName) << "h%61llo:world" << Decoded << true
|
||||
<< PrettyDecoded << "h%2561llo:world" << "http://h%2561llo%3Aworld@example.com";
|
||||
|
|
@ -3516,9 +3513,6 @@ void tst_QUrl::setComponents_data()
|
|||
QTest::newRow("invalid-host-encode") << QUrl("http://example.com")
|
||||
<< int(Host) << "ex%61mple.com" << Decoded << false
|
||||
<< PrettyDecoded << "" << "";
|
||||
QTest::newRow("invalid-authority-encode") << QUrl("http://example.com")
|
||||
<< int(Authority) << "ex%61mple.com" << Decoded << false
|
||||
<< PrettyDecoded << "" << "";
|
||||
QTest::newRow("path-encode") << QUrl("http://example.com/foo")
|
||||
<< int(Path) << "/bar%23" << Decoded << true
|
||||
<< PrettyDecoded << "/bar%2523" << "http://example.com/bar%2523";
|
||||
|
|
@ -3528,11 +3522,7 @@ void tst_QUrl::setComponents_data()
|
|||
QTest::newRow("fragment-encode") << QUrl("http://example.com/foo#z")
|
||||
<< int(Fragment) << "bar%23" << Decoded << true
|
||||
<< PrettyDecoded << "bar%2523" << "http://example.com/foo#bar%2523";
|
||||
// force decoding; note how the userinfo becomes ambiguous
|
||||
QTest::newRow("userinfo-decode") << QUrl("http://example.com")
|
||||
<< int(UserInfo) << "hello%3Aworld:}}>b9o%25kR(" << Tolerant << true
|
||||
<< FullyDecoded << "hello:world:}}>b9o%kR("
|
||||
<< "http://hello%3Aworld:%7D%7D%3Eb9o%25kR(@example.com";
|
||||
// force decoding
|
||||
QTest::newRow("username-decode") << QUrl("http://example.com")
|
||||
<< int(UserName) << "hello%3Aworld%25" << Tolerant << true
|
||||
<< FullyDecoded << "hello:world%" << "http://hello%3Aworld%25@example.com";
|
||||
|
|
|
|||
Loading…
Reference in New Issue