Fix tilde expansion in FilePath::fromUserInput

It was not working for just "~/" without additional path component.

Change-Id: I559a7771fc09d2e604f567548585a668e8809729
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Eike Ziller
2023-02-22 11:58:17 +01:00
parent 0cb5265103
commit 37ec527e6d
2 changed files with 7 additions and 4 deletions

View File

@@ -1038,10 +1038,10 @@ FilePath FilePath::fromStringWithExtension(const QString &filepath, const QStrin
*/
FilePath FilePath::fromUserInput(const QString &filePath)
{
QString clean = doCleanPath(filePath);
if (clean.startsWith(QLatin1String("~/")))
return FileUtils::homePath().pathAppended(clean.mid(2));
return FilePath::fromString(clean);
const QString expandedPath = filePath.startsWith("~/")
? (QDir::homePath() + "/" + filePath.mid(2))
: filePath;
return FilePath::fromString(doCleanPath(expandedPath));
}
/*!

View File

@@ -654,6 +654,9 @@ void tst_fileutils::fromUserInput_data()
QTest::newRow("relative") << D("./rel", "", "", "rel");
QTest::newRow("qrc") << D(":/test.txt", "", "", ":/test.txt");
QTest::newRow("qrc-no-slash") << D(":test.txt", "", "", ":test.txt");
QTest::newRow("tilde") << D("~/", "", "", QDir::homePath());
QTest::newRow("tilde-with-path") << D("~/foo", "", "", QDir::homePath() + "/foo");
QTest::newRow("tilde-only") << D("~", "", "", "~");
QTest::newRow("unc-incomplete") << D("//", "", "", "//");
QTest::newRow("unc-incomplete-only-server") << D("//server", "", "", "//server");