diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index db8008182f5..0e46b61c7d8 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -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)); } /*! diff --git a/tests/auto/utils/fileutils/tst_fileutils.cpp b/tests/auto/utils/fileutils/tst_fileutils.cpp index 033cf680bea..334a7c99e36 100644 --- a/tests/auto/utils/fileutils/tst_fileutils.cpp +++ b/tests/auto/utils/fileutils/tst_fileutils.cpp @@ -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");