From 2e1de7f3c4cab55ce6b65f945cf0f444e6bee53a Mon Sep 17 00:00:00 2001 From: David Faure Date: Sun, 6 Dec 2015 14:37:58 +0100 Subject: QUrl: revert path-normalization in setPath(). Path normalization should happen only when NormalizePathSegments is set. Use a less intrusive fix for the setPath("//path") issue that commit aba336c2b4ad8 was about. This allows fromLocalFile("/tmp/.") to keep the "/." at the end, which is useful for appending to the path later on (e.g. to get "/tmp/.hidden") Change-Id: Ibc3d4d3276c1d3aaee1774e21e24d01af38fa880 Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qurl/tst_qurl.cpp | 54 ++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 7579c6713d..031a35b380 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -79,6 +79,8 @@ private slots: void toLocalFile(); void fromLocalFile_data(); void fromLocalFile(); + void fromLocalFileNormalize_data(); + void fromLocalFileNormalize(); void macTypes(); void relative(); void compat_legacy(); @@ -1242,16 +1244,6 @@ void tst_QUrl::fromLocalFile_data() << QString::fromLatin1("/"); QTest::newRow("data7") << QString::fromLatin1("/Mambo <#5>.mp3") << QString::fromLatin1("file:///Mambo <%235>.mp3") << QString::fromLatin1("/Mambo <#5>.mp3"); - QTest::newRow("data8") << QString::fromLatin1("/a%.txt") << QString::fromLatin1("file:///a%25.txt") - << QString::fromLatin1("/a%.txt"); - QTest::newRow("data9") << QString::fromLatin1("/a%25.txt") << QString::fromLatin1("file:///a%2525.txt") - << QString::fromLatin1("/a%25.txt"); - QTest::newRow("data10") << QString::fromLatin1("/%80.txt") << QString::fromLatin1("file:///%2580.txt") - << QString::fromLatin1("/%80.txt"); - QTest::newRow("data11") << QString::fromLatin1("./a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt"); - QTest::newRow("data12") << QString::fromLatin1("././a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt"); - QTest::newRow("data13") << QString::fromLatin1("b/../a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt"); - QTest::newRow("data14") << QString::fromLatin1("/b/../a.txt") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("/a.txt"); } void tst_QUrl::fromLocalFile() @@ -1266,6 +1258,41 @@ void tst_QUrl::fromLocalFile() QCOMPARE(url.path(), thePath); } +void tst_QUrl::fromLocalFileNormalize_data() +{ + QTest::addColumn("theFile"); // should support the fromLocalFile/toLocalFile roundtrip (so no //host or windows path) + QTest::addColumn("theUrl"); + QTest::addColumn("urlWithNormalizedPath"); + + QTest::newRow("data0") << QString::fromLatin1("/a.txt") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("file:///a.txt"); + QTest::newRow("data1") << QString::fromLatin1("a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("file:a.txt"); + QTest::newRow("data8") << QString::fromLatin1("/a%.txt") << QString::fromLatin1("file:///a%25.txt") + << QString::fromLatin1("file:///a%25.txt"); + QTest::newRow("data9") << QString::fromLatin1("/a%25.txt") << QString::fromLatin1("file:///a%2525.txt") + << QString::fromLatin1("file:///a%2525.txt"); + QTest::newRow("data10") << QString::fromLatin1("/%80.txt") << QString::fromLatin1("file:///%2580.txt") + << QString::fromLatin1("file:///%2580.txt"); + QTest::newRow("data11") << QString::fromLatin1("./a.txt") << QString::fromLatin1("file:./a.txt") << QString::fromLatin1("file:a.txt"); + QTest::newRow("data12") << QString::fromLatin1("././a.txt") << QString::fromLatin1("file:././a.txt") << QString::fromLatin1("file:a.txt"); + QTest::newRow("data13") << QString::fromLatin1("b/../a.txt") << QString::fromLatin1("file:b/../a.txt") << QString::fromLatin1("file:a.txt"); + QTest::newRow("data14") << QString::fromLatin1("/b/../a.txt") << QString::fromLatin1("file:///b/../a.txt") << QString::fromLatin1("file:///a.txt"); + QTest::newRow("data15") << QString::fromLatin1("/b/.") << QString::fromLatin1("file:///b/.") << QString::fromLatin1("file:///b"); +} + +void tst_QUrl::fromLocalFileNormalize() +{ + QFETCH(QString, theFile); + QFETCH(QString, theUrl); + QFETCH(QString, urlWithNormalizedPath); + + QUrl url = QUrl::fromLocalFile(theFile); + + QCOMPARE(url.toString(QUrl::DecodeReserved), theUrl); + QCOMPARE(url.toLocalFile(), theFile); // roundtrip + QCOMPARE(url.path(), theFile); // works as well as long as we don't test windows paths + QCOMPARE(url.toString(QUrl::NormalizePathSegments), urlWithNormalizedPath); +} + void tst_QUrl::macTypes() { #ifndef Q_OS_MAC @@ -2960,6 +2987,9 @@ void tst_QUrl::fromUserInputWithCwd_data() while (it.hasNext()) { it.next(); QUrl url = QUrl::fromLocalFile(it.filePath()); + if (it.fileName() == QLatin1String(".")) { + url = QUrl::fromLocalFile(QDir::currentPath()); // fromUserInput cleans the path + } QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.fileName() << QDir::currentPath() << url << url; } QDir parent = QDir::current(); @@ -3021,6 +3051,8 @@ void tst_QUrl::fileName_data() << QString() << "tmp.txt" << "tmp.txt"; QTest::newRow("encoded") << "print:/specials/Print%20To%20File%20(PDF%252FAcrobat)" << "/specials/" << "Print To File (PDF%252FAcrobat)" << "Print To File (PDF%2FAcrobat)"; + QTest::newRow("endsWithDot") << "file:///temp/." + << "/temp/" << "." << "."; } void tst_QUrl::fileName() @@ -3513,7 +3545,7 @@ void tst_QUrl::setComponents_data() << PrettyDecoded << "/path" << "trash:/path"; QTest::newRow("path-withdotdot") << QUrl("file:///tmp") << int(Path) << "//tmp/..///root/." << Tolerant << true - << PrettyDecoded << "/root" << "file:///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 -- cgit v1.2.3