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 <thiago.macieira@intel.com>
This commit is contained in:
parent
5f03b48cb3
commit
2e1de7f3c4
@ -2470,8 +2470,10 @@ void QUrl::setPath(const QString &path, ParsingMode mode)
|
||||
mode = TolerantMode;
|
||||
}
|
||||
|
||||
data = qt_normalizePathSegments(data, false);
|
||||
d->setPath(data, 0, data.length());
|
||||
int from = 0;
|
||||
while (from < data.length() - 2 && data.midRef(from, 2) == QLatin1String("//"))
|
||||
++from;
|
||||
d->setPath(data, from, data.length());
|
||||
|
||||
// optimized out, since there is no path delimiter
|
||||
// if (path.isNull())
|
||||
|
@ -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<QString>("theFile"); // should support the fromLocalFile/toLocalFile roundtrip (so no //host or windows path)
|
||||
QTest::addColumn<QString>("theUrl");
|
||||
QTest::addColumn<QString>("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
|
||||
|
Loading…
x
Reference in New Issue
Block a user