Utils: Normalize backslashes on FilePath parsing again

Change-Id: I8ee0bc53244785d78acfad406664a907ab088301
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2022-09-13 11:52:44 +02:00
parent bd8d525d70
commit 3522097a8b
2 changed files with 19 additions and 14 deletions

View File

@@ -809,13 +809,17 @@ void FilePath::setPath(QStringView path)
m_path = path.toString();
}
void FilePath::setFromString(const QString &filename)
void FilePath::setFromString(const QString &unnormalizedFileName)
{
static const QLatin1String qtcDevSlash("__qtc_devices__/");
static const QLatin1String colonSlashSlash("://");
QString fileName = unnormalizedFileName;
if (fileName.contains('\\'))
fileName.replace('\\', '/');
const QChar slash('/');
const QStringView fileNameView(filename);
const QStringView fileNameView(fileName);
bool startsWithQtcSlashDev = false;
QStringView withoutQtcDeviceRoot = fileNameView;
@@ -848,23 +852,23 @@ void FilePath::setFromString(const QString &filename)
m_scheme.clear();
m_host.clear();
m_path = filename;
m_path = fileName;
return;
}
const int firstSlash = filename.indexOf(slash);
const int schemeEnd = filename.indexOf(colonSlashSlash);
const int firstSlash = fileName.indexOf(slash);
const int schemeEnd = fileName.indexOf(colonSlashSlash);
if (schemeEnd != -1 && schemeEnd < firstSlash) {
// This is a pseudo Url, we can't use QUrl here sadly.
m_scheme = filename.left(schemeEnd);
const int hostEnd = filename.indexOf(slash, schemeEnd + 3);
m_host = filename.mid(schemeEnd + 3, hostEnd - schemeEnd - 3);
m_scheme = fileName.left(schemeEnd);
const int hostEnd = fileName.indexOf(slash, schemeEnd + 3);
m_host = fileName.mid(schemeEnd + 3, hostEnd - schemeEnd - 3);
if (hostEnd != -1)
setPath(QStringView(filename).mid(hostEnd));
setPath(QStringView(fileName).mid(hostEnd));
return;
}
setPath(filename);
setPath(fileName);
return;
}
@@ -1599,7 +1603,7 @@ QString FilePath::shortNativePath() const
*/
bool FilePath::isRelativePath() const
{
if (m_path.startsWith('/') || m_path.startsWith('\\'))
if (m_path.startsWith('/'))
return false;
if (m_path.size() > 1 && isWindowsDriveLetter(m_path[0]) && m_path.at(1) == ':')
return false;

View File

@@ -410,9 +410,9 @@ void tst_fileutils::fromString_data()
QTest::newRow("unix-folder") << D("/tmp", "", "", "/tmp");
QTest::newRow("unix-folder-with-trailing-slash") << D("/tmp/", "", "", "/tmp/");
QTest::newRow("windows-root") << D("c:", "", "", "c:/", FailEverywhere);
QTest::newRow("windows-folder") << D("c:\\Windows", "", "", "c:/Windows", FailEverywhere);
QTest::newRow("windows-folder-with-trailing-slash") << D("c:\\Windows\\", "", "", "c:/Windows\\", FailEverywhere);
QTest::newRow("windows-root") << D("c:", "", "", "c:");
QTest::newRow("windows-folder") << D("c:\\Windows", "", "", "c:/Windows");
QTest::newRow("windows-folder-with-trailing-slash") << D("c:\\Windows\\", "", "", "c:/Windows/");
QTest::newRow("windows-folder-slash") << D("C:/Windows", "", "", "C:/Windows");
QTest::newRow("docker-root-url") << D("docker://1234/", "docker", "1234", "/");
@@ -426,6 +426,7 @@ void tst_fileutils::fromString_data()
QTest::newRow("qtc-dev-type-dev-linux") << D("/__qtc_devices__/docker/1234", "docker", "1234", "/");
QTest::newRow("qtc-dev-type-dev-win") << D("c:/__qtc_devices__/docker/1234", "docker", "1234", "/");
// "Remote Windows" is currently truly not supported.
QTest::newRow("cross-os-linux")
<< D("/__qtc_devices__/docker/1234/c:/test.txt", "docker", "1234", "c:/test.txt", FailEverywhere);
QTest::newRow("cross-os-win")