diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 0613395f2e6..aabeeab6f95 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -1430,7 +1430,8 @@ FilePath FilePath::fromStringWithExtension(const QString &filepath, const QStrin */ FilePath FilePath::fromUserInput(const QString &filePath) { - const QString expandedPath = filePath.startsWith("~/") + const QString expandedPath = filePath == "~" ? QDir::homePath() + : filePath.startsWith("~/") ? (QDir::homePath() + "/" + filePath.mid(2)) : filePath; return FilePath::fromString(doCleanPath(expandedPath)); diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index 8e941f52a34..26c190730ce 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -344,7 +344,7 @@ void PathChooser::setEnvironment(const Environment &env) FilePath PathChooser::unexpandedFilePath() const { - return FilePath::fromUserInput(d->m_lineEdit->text()); + return FilePath::fromUserInput(d->m_lineEdit->text().trimmed()); } FilePath PathChooser::filePath() const diff --git a/tests/auto/utils/filepath/tst_filepath.cpp b/tests/auto/utils/filepath/tst_filepath.cpp index 369fb6a2584..b90615a5483 100644 --- a/tests/auto/utils/filepath/tst_filepath.cpp +++ b/tests/auto/utils/filepath/tst_filepath.cpp @@ -873,7 +873,7 @@ void tst_filepath::fromUserInput_data() 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("tilde-only") << D("~", "", "", QDir::homePath()); QTest::newRow("unc-incomplete") << D("//", "", "", "//"); QTest::newRow("unc-incomplete-only-server") << D("//server", "", "", "//server");