Fix QUrl::topLevelDomain(QUrl::FullyDecoded)

qt_ACE_do(".co.uk") was returning an empty string because of the
leading dot. Allow leading dots from topLevelDomain, but not from
other calls.

Change-Id: I757d9960708e205d30554cd2bbcf618c8624792b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
David Faure 2013-07-01 15:12:36 +02:00 committed by The Qt Project
parent 691cb20d95
commit 67ec78aac1
4 changed files with 12 additions and 9 deletions

View File

@ -1059,7 +1059,7 @@ inline void QUrlPrivate::appendHost(QString &appendTo, QUrl::FormattingOptions o
// this is either an IPv4Address or a reg-name
// if it is a reg-name, it is already stored in Unicode form
if (options == QUrl::EncodeUnicode)
appendTo += qt_ACE_do(host, ToAceOnly);
appendTo += qt_ACE_do(host, ToAceOnly, AllowLeadingDot);
else
appendTo += host;
}
@ -1207,7 +1207,7 @@ inline bool QUrlPrivate::setHost(const QString &value, int from, int iend, QUrl:
return setHost(s, 0, s.length(), QUrl::StrictMode);
}
s = qt_ACE_do(QString::fromRawData(begin, len), NormalizeAce);
s = qt_ACE_do(QString::fromRawData(begin, len), NormalizeAce, ForbidLeadingDot);
if (s.isEmpty()) {
setError(InvalidRegNameError, value);
return false;
@ -2976,7 +2976,7 @@ QString QUrl::topLevelDomain(ComponentFormattingOptions options) const
{
QString tld = qTopLevelDomain(host());
if (options & EncodeUnicode) {
return qt_ACE_do(tld, ToAceOnly);
return qt_ACE_do(tld, ToAceOnly, AllowLeadingDot);
}
return tld;
}
@ -3296,7 +3296,7 @@ QString QUrl::fromEncodedComponent_helper(const QByteArray &ba)
*/
QString QUrl::fromAce(const QByteArray &domain)
{
return qt_ACE_do(QString::fromLatin1(domain), NormalizeAce);
return qt_ACE_do(QString::fromLatin1(domain), NormalizeAce, ForbidLeadingDot /*FIXME: make configurable*/);
}
/*!
@ -3317,7 +3317,7 @@ QString QUrl::fromAce(const QByteArray &domain)
*/
QByteArray QUrl::toAce(const QString &domain)
{
QString result = qt_ACE_do(domain, ToAceOnly);
QString result = qt_ACE_do(domain, ToAceOnly, ForbidLeadingDot /*FIXME: make configurable*/);
return result.toLatin1();
}

View File

@ -63,8 +63,9 @@ extern Q_AUTOTEST_EXPORT int qt_urlRecode(QString &appendTo, const QChar *begin,
QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications = 0);
// in qurlidna.cpp
enum AceLeadingDot { AllowLeadingDot, ForbidLeadingDot };
enum AceOperation { ToAceOnly, NormalizeAce };
extern QString qt_ACE_do(const QString &domain, AceOperation op);
extern QString qt_ACE_do(const QString &domain, AceOperation op, AceLeadingDot dot);
extern Q_AUTOTEST_EXPORT void qt_nameprep(QString *source, int from);
extern Q_AUTOTEST_EXPORT bool qt_check_std3rules(const QChar *uc, int len);
extern Q_AUTOTEST_EXPORT void qt_punycodeEncoder(const QChar *s, int ucLength, QString *output);

View File

@ -2461,7 +2461,7 @@ static int nextDotDelimiter(const QString &domain, int from = 0)
return ch - b;
}
QString qt_ACE_do(const QString &domain, AceOperation op)
QString qt_ACE_do(const QString &domain, AceOperation op, AceLeadingDot dot)
{
if (domain.isEmpty())
return domain;
@ -2479,7 +2479,8 @@ QString qt_ACE_do(const QString &domain, AceOperation op)
if (labelLength == 0) {
if (idx == domain.length())
break;
return QString(); // two delimiters in a row -- empty label not allowed
if (dot == ForbidLeadingDot || idx > 0)
return QString(); // two delimiters in a row -- empty label not allowed
}
// RFC 3490 says, about the ToASCII operation:

View File

@ -2863,7 +2863,8 @@ void tst_QUrl::effectiveTLDs()
{
QFETCH(QUrl, domain);
QFETCH(QString, TLD);
QCOMPARE(domain.topLevelDomain(), TLD);
QCOMPARE(domain.topLevelDomain(QUrl::PrettyDecoded), TLD);
QCOMPARE(domain.topLevelDomain(QUrl::FullyDecoded), TLD);
}
void tst_QUrl::lowercasesScheme()