forked from qt-creator/qt-creator
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:
@@ -1038,10 +1038,10 @@ FilePath FilePath::fromStringWithExtension(const QString &filepath, const QStrin
|
|||||||
*/
|
*/
|
||||||
FilePath FilePath::fromUserInput(const QString &filePath)
|
FilePath FilePath::fromUserInput(const QString &filePath)
|
||||||
{
|
{
|
||||||
QString clean = doCleanPath(filePath);
|
const QString expandedPath = filePath.startsWith("~/")
|
||||||
if (clean.startsWith(QLatin1String("~/")))
|
? (QDir::homePath() + "/" + filePath.mid(2))
|
||||||
return FileUtils::homePath().pathAppended(clean.mid(2));
|
: filePath;
|
||||||
return FilePath::fromString(clean);
|
return FilePath::fromString(doCleanPath(expandedPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@@ -654,6 +654,9 @@ void tst_fileutils::fromUserInput_data()
|
|||||||
QTest::newRow("relative") << D("./rel", "", "", "rel");
|
QTest::newRow("relative") << D("./rel", "", "", "rel");
|
||||||
QTest::newRow("qrc") << D(":/test.txt", "", "", ":/test.txt");
|
QTest::newRow("qrc") << D(":/test.txt", "", "", ":/test.txt");
|
||||||
QTest::newRow("qrc-no-slash") << 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") << D("//", "", "", "//");
|
||||||
QTest::newRow("unc-incomplete-only-server") << D("//server", "", "", "//server");
|
QTest::newRow("unc-incomplete-only-server") << D("//server", "", "", "//server");
|
||||||
|
Reference in New Issue
Block a user