From e301c82693c33c0f96c6a756d15fe35a9d877443 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 26 Apr 2010 15:16:34 +0200 Subject: QUrl: parsing of host name with an undercore. This is not supposed to be allowed, but it work with other browsers Rask-number: QTBUG-7434 Reviewed-by: Thiago Reviewed-by: Markus Goetz (cherry picked from commit a8065da96b96fcc4baeca7615c2a4195c05cbc03) --- src/corelib/io/qurl.cpp | 4 +++- tests/auto/qurl/tst_qurl.cpp | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index bdb0cfd..eb1834c 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -2990,7 +2990,9 @@ bool qt_check_std3rules(const QChar *uc, int len) // only LDH is present if (c == '-' || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') - || (c >= 'a' && c <= 'z')) + || (c >= 'a' && c <= 'z') + //underscore is not supposed to be allowed, but other browser accept it (QTBUG-7434) + || c == '_') continue; return false; diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 8dffebb..ede6cde 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -1631,6 +1631,10 @@ void tst_QUrl::toString_data() QTest::newRow("nopath_task31320") << QString::fromLatin1("host://protocol") << uint(QUrl::None) << QString::fromLatin1("host://protocol"); + + QTest::newRow("underscore_QTBUG-7434") << QString::fromLatin1("http://foo_bar.host.com/rss.php") + << uint(QUrl::None) + << QString::fromLatin1("http://foo_bar.host.com/rss.php"); } void tst_QUrl::toString() @@ -3269,7 +3273,6 @@ void tst_QUrl::std3violations_data() QTest::newRow("question") << "foo?bar" << true; QTest::newRow("at") << "foo@bar" << true; QTest::newRow("backslash") << "foo\\bar" << false; - QTest::newRow("underline") << "foo_bar" << false; // these characters are transformed by NFKC to non-LDH characters QTest::newRow("dot-like") << QString::fromUtf8("foo\342\200\244bar") << false; // U+2024 ONE DOT LEADER @@ -3314,6 +3317,7 @@ void tst_QUrl::std3deviations_data() QTest::newRow("ending-dot") << "example.com."; QTest::newRow("ending-dot3002") << QString("example.com") + QChar(0x3002); + QTest::newRow("underline") << "foo_bar"; //QTBUG-7434 } void tst_QUrl::std3deviations() -- cgit v0.12 From c3bec5fa2dfc53051bd09a6c3c1a50b7f239ab41 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 14 May 2010 10:35:33 +0200 Subject: Fix QUrl::isValid if the host contains invalid caracter. If the host contains invalid caracter, QUrl::isValid should return false Task-number: QTBUG-10355 Reviewed-by: thiago --- src/corelib/io/qurl.cpp | 10 ++++++++-- tests/auto/qurl/tst_qurl.cpp | 27 ++++++++++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index eb1834c..5119ccc 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -338,6 +338,7 @@ public: bool hasQuery; bool hasFragment; bool isValid; + bool isHostValid; char valueDelimiter; char pairDelimiter; @@ -3347,6 +3348,7 @@ QUrlPrivate::QUrlPrivate() ref = 1; port = -1; isValid = false; + isHostValid = true; parsingMode = QUrl::TolerantMode; valueDelimiter = '='; pairDelimiter = '&'; @@ -3373,6 +3375,7 @@ QUrlPrivate::QUrlPrivate(const QUrlPrivate ©) hasQuery(copy.hasQuery), hasFragment(copy.hasFragment), isValid(copy.isValid), + isHostValid(copy.isHostValid), valueDelimiter(copy.valueDelimiter), pairDelimiter(copy.pairDelimiter), stateFlags(copy.stateFlags), @@ -3403,6 +3406,8 @@ QString QUrlPrivate::canonicalHost() const that->host = host.toLower(); } else { that->host = qt_ACE_do(host, NormalizeAce); + if (that->host.isNull()) + that->isHostValid = false; } return that->host; } @@ -3479,6 +3484,7 @@ QString QUrlPrivate::authority(QUrl::FormattingOptions options) const void QUrlPrivate::setAuthority(const QString &auth) { + isHostValid = true; if (auth.isEmpty()) return; @@ -4169,7 +4175,7 @@ bool QUrl::isValid() const if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse(); if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Validated)) d->validate(); - return d->isValid; + return d->isValid && d->isHostValid; } /*! @@ -4421,7 +4427,6 @@ void QUrl::setAuthority(const QString &authority) if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse(); detach(); QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized); - d->setAuthority(authority); } @@ -4642,6 +4647,7 @@ void QUrl::setHost(const QString &host) if (!d) d = new QUrlPrivate; if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse(); detach(); + d->isHostValid = true; QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized | QUrlPrivate::HostCanonicalized); d->host = host; diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index ede6cde..3cc0d78 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -1409,7 +1409,7 @@ void tst_QUrl::setUrl() void tst_QUrl::i18n_data() { QTest::addColumn("input"); - QTest::addColumn("punyOutput"); + QTest::addColumn("punyOutput"); QTest::newRow("øl") << QString::fromLatin1("http://ole:passord@www.øl.no/index.html?ole=æsemann&ilder gud=hei#top") << QByteArray("http://ole:passord@www.xn--l-4ga.no/index.html?ole=%C3%A6semann&ilder%20gud=hei#top"); @@ -2164,25 +2164,25 @@ void tst_QUrl::toPercentEncoding_data() QTest::addColumn("includeInEncoding"); QTest::newRow("test_01") << QString::fromLatin1("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~") - << QByteArray("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~") + << QByteArray("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~") << QByteArray("") << QByteArray(""); QTest::newRow("test_02") << QString::fromLatin1("{\t\n\r^\"abc}") - << QByteArray("%7B%09%0A%0D%5E%22abc%7D") + << QByteArray("%7B%09%0A%0D%5E%22abc%7D") << QByteArray("") << QByteArray(""); QTest::newRow("test_03") << QString::fromLatin1("://?#[]@!$&'()*+,;=") - << QByteArray("%3A%2F%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D") + << QByteArray("%3A%2F%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D") << QByteArray("") << QByteArray(""); QTest::newRow("test_04") << QString::fromLatin1("://?#[]@!$&'()*+,;=") - << QByteArray("%3A%2F%2F%3F%23%5B%5D%40!$&'()*+,;=") + << QByteArray("%3A%2F%2F%3F%23%5B%5D%40!$&'()*+,;=") << QByteArray("!$&'()*+,;=") << QByteArray(""); QTest::newRow("test_05") << QString::fromLatin1("abcd") << QByteArray("a%62%63d") << QByteArray("") - << QByteArray("bc"); + << QByteArray("bc"); } void tst_QUrl::toPercentEncoding() @@ -2192,7 +2192,7 @@ void tst_QUrl::toPercentEncoding() QFETCH(QByteArray, excludeInEncoding); QFETCH(QByteArray, includeInEncoding); - QByteArray encodedUrl = QUrl::toPercentEncoding(original, excludeInEncoding, includeInEncoding); + QByteArray encodedUrl = QUrl::toPercentEncoding(original, excludeInEncoding, includeInEncoding); QCOMPARE(encodedUrl.constData(), encoded.constData()); QCOMPARE(original, QUrl::fromPercentEncoding(encodedUrl)); } @@ -2460,6 +2460,8 @@ void tst_QUrl::isValid() QUrl url = QUrl::fromEncoded("http://strange@ok-hostname/", QUrl::StrictMode); QVERIFY(!url.isValid()); // < and > are not allowed in userinfo in strict mode + url.setUserName("normal_username"); + QVERIFY(url.isValid()); } { QUrl url = QUrl::fromEncoded("http://strange@ok-hostname/"); @@ -2470,7 +2472,18 @@ void tst_QUrl::isValid() QUrl url = QUrl::fromEncoded("http://strange;hostname/here"); QVERIFY(!url.isValid()); QCOMPARE(url.path(), QString("/here")); + url.setAuthority("foobar@bar"); + QVERIFY(url.isValid()); + } + + { + QUrl url = QUrl::fromEncoded("foo://stuff;1/g"); + QVERIFY(!url.isValid()); + QCOMPARE(url.path(), QString("/g")); + url.setHost("stuff-1"); + QVERIFY(url.isValid()); } + } void tst_QUrl::schemeValidator_data() -- cgit v0.12