Utils: Fix FilePath::fromString host decoding

Previously FilePath::fromString did not decode %25 (%) and %2f (/),
so a round of ::fromString(::toString()) would not return the same host.

Change-Id: I99c7317fb149443c2e52c099f7da7c4ef6768aff
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2022-10-20 08:36:43 +02:00
parent 5c313b706f
commit 3ac5051af9
2 changed files with 61 additions and 5 deletions
@@ -104,6 +104,9 @@ private slots:
void isSameFile_data();
void isSameFile();
void hostSpecialChars_data();
void hostSpecialChars();
private:
QTemporaryDir tempDir;
QString rootPath;
@@ -1159,6 +1162,54 @@ void tst_fileutils::isSameFile()
QCOMPARE(left.isSameFile(right), shouldBeEqual);
}
void tst_fileutils::hostSpecialChars_data()
{
QTest::addColumn<QString>("scheme");
QTest::addColumn<QString>("host");
QTest::addColumn<QString>("path");
QTest::addColumn<FilePath>("expected");
QTest::addRow("slash-in-host") << "device" << "host/name" << "/" << FilePath::fromString("device://host%2fname/");
QTest::addRow("percent-in-host") << "device" << "host%name" << "/" << FilePath::fromString("device://host%25name/");
QTest::addRow("percent-and-slash-in-host") << "device" << "host/%name" << "/" << FilePath::fromString("device://host%2f%25name/");
QTest::addRow("qtc-dev-slash-in-host-linux") << "device" << "host/name" << "/" << FilePath::fromString("/__qtc_devices__/device/host%2fname/");
QTest::addRow("qtc-dev-slash-in-host-windows") << "device" << "host/name" << "/" << FilePath::fromString("c:/__qtc_devices__/device/host%2fname/");
}
void tst_fileutils::hostSpecialChars()
{
QFETCH(QString, scheme);
QFETCH(QString, host);
QFETCH(QString, path);
QFETCH(FilePath, expected);
FilePath fp;
fp.setParts(scheme, host, path);
// Check that setParts and fromString give the same result
QCOMPARE(fp, expected);
QCOMPARE(fp.host(), expected.host());
QCOMPARE(fp.host(), host);
QCOMPARE(expected.host(), host);
QString toStringExpected = expected.toString();
QString toStringActual = fp.toString();
// Check that toString gives the same result
QCOMPARE(toStringActual, toStringExpected);
// Check that fromString => toString => fromString gives the same result
FilePath toFromExpected = FilePath::fromString(expected.toString());
QCOMPARE(toFromExpected, expected);
QCOMPARE(toFromExpected, fp);
// Check that setParts => toString => fromString gives the same result
FilePath toFromActual = FilePath::fromString(fp.toString());
QCOMPARE(toFromActual, fp);
QCOMPARE(toFromExpected, expected);
}
QTEST_GUILESS_MAIN(tst_fileutils)
#include "tst_fileutils.moc"