forked from qt-creator/qt-creator
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:
@@ -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));
|
||||
|
@@ -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
|
||||
|
@@ -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");
|
||||
|
Reference in New Issue
Block a user