From fc5e8bb849232cce27d5f53491cd01628abad760 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 12 Oct 2009 23:22:54 +0200 Subject: Fix QUrl regression with setHost("::ffff:129.144.52.38") toEncoded was returning an empty host instead of [::ffff:129.144.52.38] Merge-request: 1735 Reviewed-by: Olivier Goffart --- src/corelib/io/qurl.cpp | 9 +++++++-- tests/auto/qurl/tst_qurl.cpp | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 22d0019..6001d9d 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -3874,10 +3874,15 @@ QByteArray QUrlPrivate::toEncoded(QUrl::FormattingOptions options) const } } - if (host.startsWith(QLatin1Char('['))) + if (host.startsWith(QLatin1Char('['))) { url += host.toLatin1(); - else + } else if (host.contains(QLatin1Char(':'))) { + url += '['; + url += host.toLatin1(); + url += ']'; + } else { url += QUrl::toAce(host); + } if (!(options & QUrl::RemovePort) && port != -1) { url += ':'; url += QString::number(port).toAscii(); diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 026c30e..72c13bf 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -137,6 +137,7 @@ private slots: void ipv6(); void ipv6_2_data(); void ipv6_2(); + void moreIpv6(); void toPercentEncoding_data(); void toPercentEncoding(); void isRelative_data(); @@ -2276,6 +2277,13 @@ void tst_QUrl::ipv6_2() QCOMPARE(url.toString(), output); } +void tst_QUrl::moreIpv6() +{ + QUrl waba1("http://www.kde.org/cgi/test.cgi"); + waba1.setHost("::ffff:129.144.52.38"); + QCOMPARE(QString::fromLatin1(waba1.toEncoded()), QString::fromLatin1("http://[::ffff:129.144.52.38]/cgi/test.cgi")); +} + void tst_QUrl::punycode_data() { QTest::addColumn("original"); -- cgit v0.12