Don't strip the leading slash of letter+colon paths on Unix
authorThiago Macieira <thiago.macieira@intel.com>
Mon, 23 Apr 2012 15:02:17 +0000 (17:02 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 24 Apr 2012 17:36:55 +0000 (19:36 +0200)
It's perfectly valid to have a path of /c:/a.txt on Unix, so don't
strip the leading slash unless we're on Windows.

Task-number: QTBUG-20322
Change-Id: I721bd0a65b41048bc735d4eaa0d536174164fe64
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
src/corelib/io/qurl.cpp
tests/auto/corelib/io/qurl/tst_qurl.cpp

index 3b6a7ea..ca74544 100644 (file)
@@ -2510,9 +2510,11 @@ QString QUrl::toLocalFile() const
                                                ? QLatin1Char('/') + ourPath :  ourPath);
     } else {
         tmp = ourPath;
+#ifdef Q_OS_WIN
         // magic for drives on windows
         if (ourPath.length() > 2 && ourPath.at(0) == QLatin1Char('/') && ourPath.at(2) == QLatin1Char(':'))
             tmp.remove(0, 1);
+#endif
     }
 
     return tmp;
index f9fbb8c..7e6dd14 100644 (file)
@@ -1017,7 +1017,11 @@ void tst_QUrl::toLocalFile_data()
 
     QTest::newRow("data0") << QString::fromLatin1("file:/a.txt") << QString::fromLatin1("/a.txt");
     QTest::newRow("data4") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("/a.txt");
+#ifdef Q_OS_WIN
     QTest::newRow("data5") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("c:/a.txt");
+#else
+    QTest::newRow("data5") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("/c:/a.txt");
+#endif
     QTest::newRow("data6") << QString::fromLatin1("file://somehost/somedir/somefile") << QString::fromLatin1("//somehost/somedir/somefile");
     QTest::newRow("data7") << QString::fromLatin1("file://somehost/") << QString::fromLatin1("//somehost/");
     QTest::newRow("data8") << QString::fromLatin1("file://somehost") << QString::fromLatin1("//somehost");