forked from qt-creator/qt-creator
Utils: Normalize backslashes on FilePath parsing again
Change-Id: I8ee0bc53244785d78acfad406664a907ab088301 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -809,13 +809,17 @@ void FilePath::setPath(QStringView path)
|
|||||||
m_path = path.toString();
|
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 qtcDevSlash("__qtc_devices__/");
|
||||||
static const QLatin1String colonSlashSlash("://");
|
static const QLatin1String colonSlashSlash("://");
|
||||||
|
|
||||||
|
QString fileName = unnormalizedFileName;
|
||||||
|
if (fileName.contains('\\'))
|
||||||
|
fileName.replace('\\', '/');
|
||||||
|
|
||||||
const QChar slash('/');
|
const QChar slash('/');
|
||||||
const QStringView fileNameView(filename);
|
const QStringView fileNameView(fileName);
|
||||||
|
|
||||||
bool startsWithQtcSlashDev = false;
|
bool startsWithQtcSlashDev = false;
|
||||||
QStringView withoutQtcDeviceRoot = fileNameView;
|
QStringView withoutQtcDeviceRoot = fileNameView;
|
||||||
@@ -848,23 +852,23 @@ void FilePath::setFromString(const QString &filename)
|
|||||||
|
|
||||||
m_scheme.clear();
|
m_scheme.clear();
|
||||||
m_host.clear();
|
m_host.clear();
|
||||||
m_path = filename;
|
m_path = fileName;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int firstSlash = filename.indexOf(slash);
|
const int firstSlash = fileName.indexOf(slash);
|
||||||
const int schemeEnd = filename.indexOf(colonSlashSlash);
|
const int schemeEnd = fileName.indexOf(colonSlashSlash);
|
||||||
if (schemeEnd != -1 && schemeEnd < firstSlash) {
|
if (schemeEnd != -1 && schemeEnd < firstSlash) {
|
||||||
// This is a pseudo Url, we can't use QUrl here sadly.
|
// This is a pseudo Url, we can't use QUrl here sadly.
|
||||||
m_scheme = filename.left(schemeEnd);
|
m_scheme = fileName.left(schemeEnd);
|
||||||
const int hostEnd = filename.indexOf(slash, schemeEnd + 3);
|
const int hostEnd = fileName.indexOf(slash, schemeEnd + 3);
|
||||||
m_host = filename.mid(schemeEnd + 3, hostEnd - schemeEnd - 3);
|
m_host = fileName.mid(schemeEnd + 3, hostEnd - schemeEnd - 3);
|
||||||
if (hostEnd != -1)
|
if (hostEnd != -1)
|
||||||
setPath(QStringView(filename).mid(hostEnd));
|
setPath(QStringView(fileName).mid(hostEnd));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setPath(filename);
|
setPath(fileName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1599,7 +1603,7 @@ QString FilePath::shortNativePath() const
|
|||||||
*/
|
*/
|
||||||
bool FilePath::isRelativePath() const
|
bool FilePath::isRelativePath() const
|
||||||
{
|
{
|
||||||
if (m_path.startsWith('/') || m_path.startsWith('\\'))
|
if (m_path.startsWith('/'))
|
||||||
return false;
|
return false;
|
||||||
if (m_path.size() > 1 && isWindowsDriveLetter(m_path[0]) && m_path.at(1) == ':')
|
if (m_path.size() > 1 && isWindowsDriveLetter(m_path[0]) && m_path.at(1) == ':')
|
||||||
return false;
|
return false;
|
||||||
|
@@ -410,9 +410,9 @@ void tst_fileutils::fromString_data()
|
|||||||
QTest::newRow("unix-folder") << D("/tmp", "", "", "/tmp");
|
QTest::newRow("unix-folder") << D("/tmp", "", "", "/tmp");
|
||||||
QTest::newRow("unix-folder-with-trailing-slash") << D("/tmp/", "", "", "/tmp/");
|
QTest::newRow("unix-folder-with-trailing-slash") << D("/tmp/", "", "", "/tmp/");
|
||||||
|
|
||||||
QTest::newRow("windows-root") << D("c:", "", "", "c:/", FailEverywhere);
|
QTest::newRow("windows-root") << D("c:", "", "", "c:");
|
||||||
QTest::newRow("windows-folder") << D("c:\\Windows", "", "", "c:/Windows", FailEverywhere);
|
QTest::newRow("windows-folder") << D("c:\\Windows", "", "", "c:/Windows");
|
||||||
QTest::newRow("windows-folder-with-trailing-slash") << D("c:\\Windows\\", "", "", "c:/Windows\\", FailEverywhere);
|
QTest::newRow("windows-folder-with-trailing-slash") << D("c:\\Windows\\", "", "", "c:/Windows/");
|
||||||
QTest::newRow("windows-folder-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", "/");
|
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-linux") << D("/__qtc_devices__/docker/1234", "docker", "1234", "/");
|
||||||
QTest::newRow("qtc-dev-type-dev-win") << D("c:/__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")
|
QTest::newRow("cross-os-linux")
|
||||||
<< D("/__qtc_devices__/docker/1234/c:/test.txt", "docker", "1234", "c:/test.txt", FailEverywhere);
|
<< D("/__qtc_devices__/docker/1234/c:/test.txt", "docker", "1234", "c:/test.txt", FailEverywhere);
|
||||||
QTest::newRow("cross-os-win")
|
QTest::newRow("cross-os-win")
|
||||||
|
Reference in New Issue
Block a user