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;
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)
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;
// 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))) { // '%'
}
// 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);
}
}
- 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;
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
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('['))) {
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;
// 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);
QTest::newRow("invalid-password") << "http://user:pass\x7F@ok-hostname" << "Invalid password";
QTest::newRow("invalid-regname") << "http://bad<hostname>" << "Hostname contains invalid characters";
+ QTest::newRow("invalid-regname-2") << "http://b%61d" << "Hostname contains invalid characters";
QTest::newRow("invalid-ipv6") << "http://[:::]" << "Invalid IPv6 address";
QTest::newRow("invalid-ipvfuture-1") << "http://[v7]" << "Invalid IPvFuture address";
QTest::newRow("invalid-ipvfuture-2") << "http://[v7.]" << "Invalid IPvFuture address";
QVERIFY(url.isValid());
QCOMPARE(QString(url.toEncoded()), QString("http://strange%3Cusername%3E@hostname/"));
}
+
+ {
+ QUrl url;
+ url.setUrl("http://en%63o%64%65%64.hostname/", QUrl::TolerantMode);
+ QVERIFY(url.isValid());
+ QCOMPARE(url.toString(), QString("http://encoded.hostname/"));
+ }
}
void tst_QUrl::correctEncodedMistakes_data()
QTest::newRow("invalid-host-1") << QUrl("http://example.com")
<< int(Host) << "-not-valid-" << Tolerant << false
<< PrettyDecoded << "" << "";
+ QTest::newRow("invalid-host-2") << QUrl("http://example.com")
+ << int(Host) << "%31%30.%30.%30.%31" << Strict << false
+ << PrettyDecoded << "" << "";
+ QTest::newRow("invalid-authority-1") << QUrl("http://example.com")
+ << int(Authority) << "-not-valid-" << Tolerant << false
+ << PrettyDecoded << "" << "";
+ QTest::newRow("invalid-authority-2") << QUrl("http://example.com")
+ << int(Authority) << "%31%30.%30.%30.%31" << Strict << false
+ << PrettyDecoded << "" << "";
QTest::newRow("invalid-path-1") << QUrl("/relative")
<< int(Path) << "c:/" << Strict << false
<< PrettyDecoded << "" << "";
QTest::newRow("password-encode") << QUrl("http://example.com")
<< int(Password) << "h%61llo:world@" << Decoded << true
<< PrettyDecoded << "h%2561llo:world@" << "http://:h%2561llo:world%40@example.com";
- // '%' characters are not permitted in the hostname, this tests that it fails to set anything
+ // '%' characters are not permitted in the hostname, these test that it fails to set anything
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";
QCOMPARE(copy.host(QUrl::ComponentFormattingOptions(encoding)), output);
break;
+ case Authority:
+ copy.setAuthority(newValue, QUrl::ParsingMode(parsingMode));
+ QCOMPARE(copy.authority(QUrl::ComponentFormattingOptions(encoding)), output);
+ break;
+
case Query:
copy.setQuery(newValue, QUrl::ParsingMode(parsingMode));
QCOMPARE(copy.hasQuery(), !newValue.isNull());