summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qurl
diff options
context:
space:
mode:
authorJoni Poikelin <joni.poikelin@qt.io>2018-12-11 11:42:34 +0200
committerJoni Poikelin <joni.poikelin@qt.io>2018-12-13 05:23:12 +0000
commiteaf4438b3511c8380b9b691b656a87a60e342e29 (patch)
tree7b853fef8105d7250a3cc349dc3615cbd798cec2 /tests/auto/corelib/io/qurl
parentbc997b856aa7b0b2137b568cd3fc6f190cd89f84 (diff)
Make url normalization closer to common browser behavior
Firefox, Chrome and various http libraries normalize /./ and /../ from urls, but retain multiple adjacent slashes as is. Qt removes duplicated slashes which makes it impossible to access some web resources that rely on those. Fixes: QTBUG-71973 Change-Id: Ie18ae6ad3264acb252fcd87a754726a8c546e5ec Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io/qurl')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 84af1c255a..4f173d2dfd 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -182,6 +182,8 @@ private slots:
void matches();
void ipv6_zoneId_data();
void ipv6_zoneId();
+ void normalizeRemotePaths_data();
+ void normalizeRemotePaths();
private:
void testThreadingHelper();
@@ -323,7 +325,7 @@ void tst_QUrl::comparison()
QUrl url3bis = QUrl::fromEncoded("example://a/b/c/%7Bfoo%7D/");
QUrl url3bisNoSlash = QUrl::fromEncoded("example://a/b/c/%7Bfoo%7D");
- QUrl url4bis = QUrl::fromEncoded("example://a/.//b/../b/c//%7Bfoo%7D/");
+ QUrl url4bis = QUrl::fromEncoded("example://a/./b/../b/c/%7Bfoo%7D/");
QCOMPARE(url4bis.adjusted(QUrl::NormalizePathSegments), url3bis);
QCOMPARE(url4bis.adjusted(QUrl::NormalizePathSegments | QUrl::StripTrailingSlash), url3bisNoSlash);
QVERIFY(url3bis.matches(url4bis, QUrl::NormalizePathSegments));
@@ -335,7 +337,7 @@ void tst_QUrl::comparison()
QCOMPARE(url4EncodedDots.path(QUrl::FullyDecoded), QString("/.//b/..//b/c/"));
QCOMPARE(QString::fromLatin1(url4EncodedDots.toEncoded()), QString::fromLatin1("example://a/.//b/..%2F/b/c/"));
QCOMPARE(url4EncodedDots.toString(), QString("example://a/.//b/..%2F/b/c/"));
- QCOMPARE(url4EncodedDots.adjusted(QUrl::NormalizePathSegments).toString(), QString("example://a/b/..%2F/b/c/"));
+ QCOMPARE(url4EncodedDots.adjusted(QUrl::NormalizePathSegments).toString(), QString("example://a//b/..%2F/b/c/"));
// 6.2.2.1 Make sure hexdecimal characters in percent encoding are
// treated case-insensitively
@@ -4201,6 +4203,36 @@ void tst_QUrl::ipv6_zoneId()
QCOMPARE(url.toString(QUrl::FullyEncoded), "x://[" + encodedHost + "]");
}
+void tst_QUrl::normalizeRemotePaths_data()
+{
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QString>("expected");
+
+ QTest::newRow("dotdot-slashslash") << QUrl("http://qt-project.org/some/long/..//path") << "http://qt-project.org/some//path";
+ QTest::newRow("slashslash-dotdot") << QUrl("http://qt-project.org/some//../path") << "http://qt-project.org/some/path";
+ QTest::newRow("slashslash-dotdot2") << QUrl("http://qt-project.org/some//path/../") << "http://qt-project.org/some//";
+ QTest::newRow("dot-slash") << QUrl("http://qt-project.org/some/./path") << "http://qt-project.org/some/path";
+ QTest::newRow("slashslash-dot-slashslash") << QUrl("http://qt-project.org/some//.//path") << "http://qt-project.org/some///path";
+ QTest::newRow("dot-slashslash") << QUrl("http://qt-project.org/some/.//path") << "http://qt-project.org/some//path";
+ QTest::newRow("multiple-slashes") << QUrl("http://qt-project.org/some//path") << "http://qt-project.org/some//path";
+ QTest::newRow("multiple-slashes4") << QUrl("http://qt-project.org/some////path") << "http://qt-project.org/some////path";
+ QTest::newRow("slashes-at-end") << QUrl("http://qt-project.org/some//") << "http://qt-project.org/some//";
+ QTest::newRow("dot-dotdot") << QUrl("http://qt-project.org/path/./../") << "http://qt-project.org/";
+ QTest::newRow("slash-dot-slash-dot-slash") << QUrl("http://qt-project.org/path//.//.//") << "http://qt-project.org/path////";
+ QTest::newRow("dotdot") << QUrl("http://qt-project.org/../") << "http://qt-project.org/";
+ QTest::newRow("dotdot-dotdot") << QUrl("http://qt-project.org/path/../../") << "http://qt-project.org/";
+ QTest::newRow("dot-dotdot-tail") << QUrl("http://qt-project.org/stem/path/./../tail") << "http://qt-project.org/stem/tail";
+ QTest::newRow("slash-dotdot-slash-tail") << QUrl("http://qt-project.org/stem/path//..//tail") << "http://qt-project.org/stem/path//tail";
+}
+
+void tst_QUrl::normalizeRemotePaths()
+{
+ QFETCH(QUrl, url);
+ QFETCH(QString, expected);
+
+ QCOMPARE(url.adjusted(QUrl::NormalizePathSegments).toString(), expected);
+}
+
QTEST_MAIN(tst_QUrl)
#include "tst_qurl.moc"