PathChooser: Fix handling of ~

- Just "~" should be expanded to home path, not requiring a slash "~/"
- Be resistant to spaces at start and end. This is usually a user
  mistake.

Fixes: QTCREATORBUG-31432
Change-Id: I7a286b9d2bc426e6950782f96725bb5d8fbbc075
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Eike Ziller
2024-09-02 15:44:26 +02:00
parent 1045db6791
commit c7c99d5bad
3 changed files with 4 additions and 3 deletions

View File

@@ -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));

View File

@@ -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

View File

@@ -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");