aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autotests/kconfigtest.cpp3
-rw-r--r--src/core/kconfiggroup.cpp17
2 files changed, 10 insertions, 10 deletions
diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp
index 77d0ddde..49b60f55 100644
--- a/autotests/kconfigtest.cpp
+++ b/autotests/kconfigtest.cpp
@@ -83,6 +83,7 @@ static const QVariantList s_variantlist_entry2{s_point_entry, s_size_entry};
static const QString s_homepath{homePath() + QLatin1String{"/foo"}};
static const QString s_homepath_escape{homePath() + QLatin1String("/foo/$HOME")};
+static const QString s_canonical_homepath{QFileInfo(homePath()).canonicalFilePath() + QLatin1String("/foo")};
static const QString s_dollargroup{QStringLiteral("$i")};
static const QString s_test_subdir{QStringLiteral("kconfigtest_subdir/")};
static const QString s_kconfig_test_subdir(s_test_subdir + QLatin1String("kconfigtest"));
@@ -189,6 +190,7 @@ void KConfigTest::initTestCase()
cg = KConfigGroup(&sc, "Path Type");
cg.writePathEntry("homepath", s_homepath);
cg.writePathEntry("homepathescape", s_homepath_escape);
+ cg.writePathEntry("canonicalHomePath", s_canonical_homepath);
cg = KConfigGroup(&sc, "Enum Types");
#if defined(_MSC_VER) && _MSC_VER == 1600
@@ -507,6 +509,7 @@ void KConfigTest::testPath()
KConfigGroup sc3(&sc2, "Path Type");
QCOMPARE(sc3.readPathEntry(QStringLiteral("homepath"), QString{}), s_homepath);
QCOMPARE(sc3.readPathEntry(QStringLiteral("homepathescape"), QString{}), s_homepath_escape);
+ QCOMPARE(sc3.readPathEntry(QStringLiteral("canonicalHomePath"), QString{}), s_canonical_homepath);
QCOMPARE(sc3.entryMap().value(QStringLiteral("homepath")), s_homepath);
qputenv("WITHSLASH", "/a/");
diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp
index 8b7cd863..f3ab2202 100644
--- a/src/core/kconfiggroup.cpp
+++ b/src/core/kconfiggroup.cpp
@@ -425,16 +425,13 @@ static QString translatePath(QString path) // krazy:exclude=passbyvalue
return path;
}
- // we can not use KGlobal::dirs()->relativeLocation("home", path) here,
- // since it would not recognize paths without a trailing '/'.
- // All of the 3 following functions to return the user's home directory
- // can return different paths. We have to test all them.
- const QString homeDir0 = QFile::decodeName(qgetenv("HOME"));
- const QString homeDir1 = QDir::homePath();
- const QString homeDir2 = QDir(homeDir1).canonicalPath();
- if (cleanHomeDirPath(path, homeDir0) || cleanHomeDirPath(path, homeDir1) || cleanHomeDirPath(path, homeDir2)) {
- // qDebug() << "Path was replaced\n";
- }
+ // Use the same thing as what expandString() will do, to keep data intact
+#ifdef Q_OS_WIN
+ const QString homeDir = QDir::homePath();
+#else
+ const QString homeDir = QFile::decodeName(qgetenv("HOME"));
+#endif
+ (void)cleanHomeDirPath(path, homeDir);
if (startsWithFile) {
path = QUrl::fromLocalFile(path).toString();