summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qurl/tst_qurl.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-09-21 13:27:51 -0700
committerThiago Macieira <thiago.macieira@intel.com>2017-10-06 03:49:40 +0000
commitf62768d046528636789f901ac79e2cfa1843a7b7 (patch)
treec3ae2dd1df60afb40db5af37a3ec63aaa4caa74c /tests/auto/corelib/io/qurl/tst_qurl.cpp
parent70ee08951a7ff225b47829d9d2a0ee25a68725f7 (diff)
QUrl: re-fix the setPath("//path") case leading to scheme://path
Commits aba336c2b4ad8926dc8a000718bbb7f8a6d5a72d (in Qt 5.2) and aba336c2b4ad8926dc8a000718bbb7f8a6d5a72d (in 5.6) both tried to deal with this problem, with different levels of success. This is the third attempt (and hopefully the charm). Instead of modifying the path that the user provides, go straight ahead and declare it invalid. This is supported by RFC 3986, which declares this expansion impossible: relative-part = "//" authority path-abempty / path-absolute / path-noscheme / path-empty path-abempty = *( "/" segment ) path-absolute = "/" [ segment-nz *( "/" segment ) ] path-noscheme = segment-nz-nc *( "/" segment ) The "path-abempty" and "path-noscheme" cases are the two issues we already handle. This commit adds the third one: path-absolute, which requires that the first segment of the path be of non-zero length. That is, it is now possible again to have http://example.com//path constructed piece-wise, without it producing http://example.com/path. Additionally, it catches the case of http://example.com//path parsed from full URL then followed by setAuthority(""). Change-Id: I69f37f9304f24709a823fffd14e67a5e7212ddcd Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests/auto/corelib/io/qurl/tst_qurl.cpp')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index c5647752fd..1ff85fc6dc 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -2075,6 +2075,14 @@ void tst_QUrl::isValid()
}
{
+ QUrl url("http:");
+ url.setPath("//example.com");
+ QVERIFY(!url.isValid());
+ QVERIFY(url.toString().isEmpty());
+ QVERIFY(url.errorString().contains("Path component starts with '//' and authority is absent"));
+ }
+
+ {
QUrl url;
url.setPath("http://example.com");
QVERIFY(!url.isValid());
@@ -3649,12 +3657,12 @@ void tst_QUrl::setComponents_data()
QTest::newRow("path-%3A-before-slash") << QUrl()
<< int(Path) << "c%3A/" << Tolerant << true
<< PrettyDecoded << "c%3A/" << "c%3A/";
- QTest::newRow("path-doubleslash") << QUrl("trash:/")
+ QTest::newRow("path-doubleslash") << QUrl("http://example.com")
<< int(Path) << "//path" << Tolerant << true
- << PrettyDecoded << "/path" << "trash:/path";
+ << PrettyDecoded << "//path" << "http://example.com//path";
QTest::newRow("path-withdotdot") << QUrl("file:///tmp")
<< int(Path) << "//tmp/..///root/." << Tolerant << true
- << PrettyDecoded << "/tmp/..///root/." << "file:///tmp/..///root/.";
+ << PrettyDecoded << "//tmp/..///root/." << "file:////tmp/..///root/.";
// the other fields can be present and be empty
// that is, their delimiters would be present, but there would be nothing to one side
@@ -3777,6 +3785,9 @@ void tst_QUrl::setComponents_data()
QTest::newRow("invalid-path-2") << QUrl("http://example.com")
<< int(Path) << "relative" << Strict << false
<< PrettyDecoded << "relative" << "";
+ QTest::newRow("invalid-path-3") << QUrl("trash:/")
+ << int(Path) << "//path" << Tolerant << false
+ << PrettyDecoded << "//path" << "";
// -- test bad percent encoding --
// unnecessary to test the scheme, since percent-decoding is not performed in it;