summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2011-12-28 15:59:47 -0200
committerQt by Nokia <qt-info@nokia.com>2012-03-30 01:19:59 +0200
commit329ee8cedc78de5304a84e0b205b08f39e439411 (patch)
tree146167cd8f1f6781d0d5800274c085b9383b4c03 /tests/auto/corelib/io
parentcff38329aa8635ac8a0696b0aa78782fe5605d16 (diff)
Reimplement the StrictMode URL parsing
The strict mode check is now implemented after the tolerant parser has finished, and only if the tolerant parser has not found any errors. We catch the use of disallowed characters (control characters plus a few not permitted anywhere) and broken percent encodings. We do not catch the use of Unicode characters, as they are permitted in IRIs. In the tests, remove the old errorString test since it makes little sense. Change-Id: I8261a2ccad031ad68fc6377a206e59c9db89fb38 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp75
1 files changed, 55 insertions, 20 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 259e7570fa..7e06dd4e88 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -122,6 +122,8 @@ private slots:
void schemeValidator_data();
void schemeValidator();
void invalidSchemeValidator();
+ void strictParser_data();
+ void strictParser();
void tolerantParser();
void correctEncodedMistakes_data();
void correctEncodedMistakes();
@@ -143,7 +145,6 @@ private slots:
void toEncoded();
void setAuthority_data();
void setAuthority();
- void errorString();
void clear();
void resolvedWithAbsoluteSchemes() const;
void resolvedWithAbsoluteSchemes_data() const;
@@ -1594,7 +1595,6 @@ void tst_QUrl::isValid()
}
{
QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/", QUrl::StrictMode);
- QEXPECT_FAIL("", "StrictMode not implemented yet", Continue);
QVERIFY(!url.isValid());
// < and > are not allowed in userinfo in strict mode
url.setUserName("normal_username");
@@ -1604,6 +1604,7 @@ void tst_QUrl::isValid()
QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/");
QVERIFY(url.isValid());
// < and > are allowed in tolerant mode
+ QCOMPARE(url.toEncoded(), QByteArray("http://strange%3Cusername%3E@ok-hostname/"));
}
{
QUrl url = QUrl::fromEncoded("http://strange;hostname/here");
@@ -1710,6 +1711,55 @@ void tst_QUrl::invalidSchemeValidator()
}
}
+void tst_QUrl::strictParser_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("needle");
+
+ // cannot test bad schemes here, as they are parsed as paths instead
+ //QTest::newRow("invalid-scheme") << "ht%://example.com" << "Invalid scheme";
+ //QTest::newRow("empty-scheme") << ":/" << "Empty scheme";
+
+ QTest::newRow("invalid-user1") << "http://bad<user_name>@ok-hostname" << "Invalid user name";
+ QTest::newRow("invalid-user2") << "http://bad%@ok-hostname" << "Invalid user name";
+
+ QTest::newRow("invalid-password") << "http://user:pass\x7F@ok-hostname" << "Invalid password";
+
+ QTest::newRow("invalid-regname") << "http://bad<hostname>" << "Hostname contains invalid characters";
+ QTest::newRow("invalid-ipv6") << "http://[:::]" << "Invalid IPv6 address";
+ QTest::newRow("invalid-ipvfuture-1") << "http://[v7]" << "Invalid IPvFuture address";
+ QTest::newRow("invalid-ipvfuture-2") << "http://[v7.]" << "Invalid IPvFuture address";
+ QTest::newRow("invalid-ipvfuture-3") << "http://[v789]" << "Invalid IPvFuture address";
+ QTest::newRow("unbalanced-brackets") << "http://[ff02::1" << "Expected ']'";
+
+ QTest::newRow("empty-port") << "http://example.com:" << "Invalid port";
+ QTest::newRow("invalid-port-1") << "http://example.com:-1" << "Invalid port";
+ QTest::newRow("invalid-port-2") << "http://example.com:abc" << "Invalid port";
+ QTest::newRow("invalid-port-3") << "http://example.com:9a" << "Invalid port";
+ QTest::newRow("port-range") << "http://example.com:65536" << "out of range";
+
+ QTest::newRow("invalid-path") << "foo:/path%\x1F" << "Invalid path";
+ // not yet checked:
+ //QTest::newRow("path-colon-before-slash") << "foo::/" << "':' before any '/'";
+
+ QTest::newRow("invalid-query") << "foo:?\\#" << "Invalid query";
+
+ QTest::newRow("invalid-fragment") << "#{}" << "Invalid fragment";
+}
+
+void tst_QUrl::strictParser()
+{
+ QFETCH(QString, input);
+ QFETCH(QString, needle);
+
+ QUrl url(input, QUrl::StrictMode);
+ QVERIFY(!url.isValid());
+ QVERIFY(!url.errorString().isEmpty());
+ if (!url.errorString().contains(needle))
+ qWarning("Error string changed and does not contain \"%s\" anymore: %s",
+ qPrintable(needle), qPrintable(url.errorString()));
+}
+
void tst_QUrl::tolerantParser()
{
{
@@ -1718,18 +1768,16 @@ void tst_QUrl::tolerantParser()
QCOMPARE(url.path(), QString("/path with spaces.html"));
QCOMPARE(url.toString(QUrl::FullyEncoded), QString("http://www.example.com/path%20with%20spaces.html"));
url.setUrl("http://www.example.com/path%20with spaces.html", QUrl::StrictMode);
- QEXPECT_FAIL("", "StrictMode not implemented yet", Continue);
QVERIFY(!url.isValid());
- QEXPECT_FAIL("", "StrictMode not implemented yet", Continue);
- QCOMPARE(url.toString(QUrl::FullyEncoded), QString("http://www.example.com/path%2520with%20spaces.html"));
+ QCOMPARE(url.toString(QUrl::FullyEncoded), QString("http://www.example.com/path%20with%20spaces.html"));
}
{
QUrl url = QUrl::fromEncoded("http://www.example.com/path%20with spaces.html");
QVERIFY(url.isValid());
QCOMPARE(url.path(), QString("/path with spaces.html"));
url.setEncodedUrl("http://www.example.com/path%20with spaces.html", QUrl::StrictMode);
- QEXPECT_FAIL("", "StrictMode not implemented yet", Continue);
- QVERIFY(!url.isValid());
+ QVERIFY(url.isValid());
+ QCOMPARE(url.toString(QUrl::FullyEncoded), QString("http://www.example.com/path%20with%20spaces.html"));
}
{
@@ -2209,19 +2257,6 @@ void tst_QUrl::setAuthority()
QCOMPARE(u.toString(), url);
}
-void tst_QUrl::errorString()
-{
- QUrl v;
- QCOMPARE(v.errorString(), QString());
-
- QUrl u = QUrl::fromEncoded("http://strange<username>@bad_hostname/", QUrl::StrictMode);
- QEXPECT_FAIL("", "StrictMode not implemented yet", Abort);
- QVERIFY(!u.isValid());
- QString errorString = "Invalid URL \"http://strange<username>@bad_hostname/\": "
- "error at position 14: expected end of URL, but found '<'";
- QCOMPARE(u.errorString(), errorString);
-}
-
void tst_QUrl::clear()
{
QUrl url("a");