From 74412088d5b0d2ac3f1ad56a46cdffb206311c5f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 23 Apr 2017 22:43:18 -0300 Subject: QUrl: fix IDN whitelist checking when the TLD is in Unicode The whitelist is kept in ACE form, so if the TLD came in Unicode, we need to run ToASCII before we can check the whitelist. This is slightly inefficient because we'll run the same operation later in this domain. Change-Id: Iadfecb6f28984634979dfffd14b831f37b0f4818 Reviewed-by: Lars Knoll Reviewed-by: Florian Bruhin (cherry picked from commit 21dd5d314a75c09250448e5d59dfb9af88c0f7d5) --- src/corelib/io/qurlidna.cpp | 4 ++-- tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qurlidna.cpp b/src/corelib/io/qurlidna.cpp index 46553d38a5..eae4289cf5 100644 --- a/src/corelib/io/qurlidna.cpp +++ b/src/corelib/io/qurlidna.cpp @@ -2415,8 +2415,8 @@ static bool qt_is_idn_enabled(const QString &domain) return false; int len = domain.size() - idx - 1; - QString tldString(domain.constData() + idx + 1, len); - qt_nameprep(&tldString, 0); + QString tldString = qt_ACE_do(QString::fromRawData(domain.constData() + idx + 1, len), ToAceOnly, ForbidLeadingDot); + len = tldString.size(); const QChar *tld = tldString.constData(); diff --git a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp index 753a679d4c..8c9627b220 100644 --- a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp +++ b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp @@ -675,6 +675,14 @@ void tst_QUrlInternal::ace_testsuite() QCOMPARE(QUrl::fromAce(domain.toLatin1()), fromace + suffix); QCOMPARE(QUrl::fromAce(QUrl::toAce(domain)), unicode + suffix); + QUrl u; + u.setHost(domain); + QVERIFY(u.isValid()); + QCOMPARE(u.host(), unicode + suffix); + QCOMPARE(u.host(QUrl::EncodeUnicode), toace + suffix); + QCOMPARE(u.toEncoded(), "//" + toace.toLatin1() + suffix); + QCOMPARE(u.toDisplayString(), "//" + unicode + suffix); + domain = in + (suffix ? ".troll.No" : ""); QCOMPARE(QString::fromLatin1(QUrl::toAce(domain)), toace + suffix); if (fromace != ".") -- cgit v1.2.3