summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2013-07-24 22:54:44 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-21 23:50:33 +0200
commitf874a5dd8b42a346ee7d036c4de78a9da26f961d (patch)
treec8fcb3ede14ea0777d8e46003eaeebafcbee07c3
parent028def2ada208b16d308765febcd64874b779c11 (diff)
QUrl: fix host(FullyDecoded), it shouldn't trigger EncodeUnicode.
Change-Id: I9a62d5eb8b099b659cfcfc591c983b3d73ca9569 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/io/qurl.cpp7
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp25
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<QString>("urlStr");
+ QTest::addColumn<QUrl::FormattingOptions>("options");
+ QTest::addColumn<QString>("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()
{
{