diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp --- a/autotests/kconfigtest.cpp +++ b/autotests/kconfigtest.cpp @@ -521,7 +521,9 @@ << "withBraces[$e]=file://${HOME}/foo" << endl << "URL[$e]=file://${HOME}/foo" << endl << "hostname[$e]=$(hostname)" << endl - << "noeol=foo"; // no EOL + << "escapes=aaa,bb/b,ccc\\,ccc" << endl + << "noeol=foo" // no EOL + ; } KConfig cf2(TEST_SUBDIR "pathtest"); KConfigGroup group = cf2.group("Test Group"); @@ -547,6 +549,9 @@ #endif QVERIFY(group.hasKey("noeol")); QCOMPARE(group.readEntry("noeol", QString()), QString("foo")); + + const auto val = QStringList { QStringLiteral("aaa"), QStringLiteral("bb/b"), QStringLiteral("ccc,ccc")}; + QCOMPARE(group.readPathEntry("escapes", QStringList()), val); } void KConfigTest::testPersistenceOfExpandFlagForPath() diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp --- a/src/core/kconfiggroup.cpp +++ b/src/core/kconfiggroup.cpp @@ -160,25 +160,24 @@ return QStringList(QString()); } QStringList value; - QString val; - val.reserve(data.size()); - bool quoted = false; - for (int p = 0; p < data.length(); p++) { - if (quoted) { - val += data[p]; - quoted = false; - } else if (data[p].unicode() == '\\') { - quoted = true; - } else if (data[p].unicode() == ',') { - val.squeeze(); // release any unused memory - value.append(val); - val.clear(); - val.reserve(data.size() - p); - } else { - val += data[p]; + QVector escapedAt; + bool escapedLast = false; + int last = 0; + for (int p = 0; p < data.length() + 1; p++) { + if (escapedLast) { + escapedLast = false; + } else if (data.size() == p || data[p] == QLatin1Char(',')) { + auto str = data.mid(last, p-last); + while (!escapedAt.isEmpty()) { + str.remove(escapedAt.takeLast(), 1); + } + value.append(str); + last = p + 1; + } else if (p < data.size() && data[p] == QLatin1Char('\\')) { + escapedLast = true; + escapedAt.append(p-last); } } - value.append(val); return value; } diff --git a/src/core/kconfigini.cpp b/src/core/kconfigini.cpp --- a/src/core/kconfigini.cpp +++ b/src/core/kconfigini.cpp @@ -793,6 +793,12 @@ r++; *r = ';'; break; + case ',': + // not really an escape sequence, but allowed in .desktop files, don't strip '\,' from the string + *r = '\\'; + r++; + *r = ','; + break; case 'x': if (i + 2 < l) { *r = charFromHex(str + i + 1, file, line);