From f874a5dd8b42a346ee7d036c4de78a9da26f961d Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 24 Jul 2013 22:54:44 +0200 Subject: [PATCH] QUrl: fix host(FullyDecoded), it shouldn't trigger EncodeUnicode. Change-Id: I9a62d5eb8b099b659cfcfc591c983b3d73ca9569 Reviewed-by: Thiago Macieira --- src/corelib/io/qurl.cpp | 7 +++++-- tests/auto/corelib/io/qurl/tst_qurl.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 9607f14853..f33e446a98 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -1089,8 +1089,11 @@ inline void QUrlPrivate::setQuery(const QString &value, int from, int iend) inline void QUrlPrivate::appendHost(QString &appendTo, QUrl::FormattingOptions options) const { - // this is the only flag that matters - options &= QUrl::EncodeUnicode; + // EncodeUnicode is the only flag that matters + if ((options & QUrl::FullyDecoded) == QUrl::FullyDecoded) + options = 0; + else + options &= QUrl::EncodeUnicode; if (host.isEmpty()) return; if (host.at(0).unicode() == '[') { diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 2817e6d22c..9e4d02d3d1 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -148,6 +148,8 @@ private slots: void stripTrailingSlash(); void hosts_data(); void hosts(); + void hostFlags_data(); + void hostFlags(); void setPort(); void toEncoded_data(); void toEncoded(); @@ -2637,6 +2639,29 @@ void tst_QUrl::hosts() QTEST(QUrl(url).host(), "host"); } +void tst_QUrl::hostFlags_data() +{ + QTest::addColumn("urlStr"); + QTest::addColumn("options"); + QTest::addColumn("expectedHost"); + + QString swedish = QString::fromUtf8("http://www.räksmörgås.se/pub?a=b&a=dø&a=f#vræl"); + QTest::newRow("se_fullydecoded") << swedish << QUrl::FormattingOptions(QUrl::FullyDecoded) << QString::fromUtf8("www.räksmörgås.se"); + QTest::newRow("se_fullyencoded") << swedish << QUrl::FormattingOptions(QUrl::FullyEncoded) << QString::fromUtf8("www.xn--rksmrgs-5wao1o.se"); + QTest::newRow("se_prettydecoded") << swedish << QUrl::FormattingOptions(QUrl::PrettyDecoded) << QString::fromUtf8("www.räksmörgås.se"); + QTest::newRow("se_encodespaces") << swedish << QUrl::FormattingOptions(QUrl::EncodeSpaces) << QString::fromUtf8("www.räksmörgås.se"); +} + +void tst_QUrl::hostFlags() +{ + QFETCH(QString, urlStr); + QFETCH(QUrl::FormattingOptions, options); + QFETCH(QString, expectedHost); + + QUrl url(urlStr); + QCOMPARE(url.host(options), expectedHost); +} + void tst_QUrl::setPort() { {