Fix reading of XDG style semicolon separated lists with escaped ';'

Previously the warning "Invalid escape sequence "\;"." would appear and
"\;" was replaced with just the backslash as is done for all
unrecognized escape sequences. Keep both characters so that
readXdgListEntry() works with values containing semicolons

REVIEW: 119074
wilder
Alex Richardson 12 years ago
parent fde2f3c847
commit ae51450ea6
  1. 27
      autotests/kconfigtest.cpp
  2. 1
      autotests/kconfigtest.h
  3. 18
      autotests/kdesktopfiletest.cpp
  4. 6
      src/core/kconfigini.cpp

@ -1672,6 +1672,33 @@ void KConfigTest::testNewlines()
}
void KConfigTest::testXdgListEntry()
{
QTemporaryFile file;
QVERIFY(file.open());
QTextStream out(&file);
out << "[General]" << endl
<< "Key1=" << endl // empty list
// emtpty entries
<< "Key2=;" << endl
<< "Key3=;;" << endl
<< "Key4=;;;" << endl
<< "Key5=\\;" << endl
<< "Key6=1;2\\;3;;" << endl;
out.flush();
file.close();
KConfig anonConfig(file.fileName(), KConfig::SimpleConfig);
KConfigGroup grp = anonConfig.group("General");
QStringList invalidList; // use this as a default when an empty list is expected
invalidList << "Error! Default value read!";
QCOMPARE(grp.readXdgListEntry("Key1", invalidList), QStringList());
QCOMPARE(grp.readXdgListEntry("Key2", invalidList), QStringList() << QString());
QCOMPARE(grp.readXdgListEntry("Key3", invalidList), QStringList() << QString() << QString());
QCOMPARE(grp.readXdgListEntry("Key4", invalidList), QStringList()<< QString() << QString() << QString());
QCOMPARE(grp.readXdgListEntry("Key5", invalidList), QStringList() << ";");
QCOMPARE(grp.readXdgListEntry("Key6", invalidList), QStringList() << "1" << "2;3" << QString());
}
#include <QThreadPool>
#include <qtconcurrentrun.h>

@ -76,6 +76,7 @@ private Q_SLOTS:
void testDirtyAfterRevert();
void testKdeGlobals();
void testNewlines();
void testXdgListEntry();
void testThreads();

@ -142,21 +142,35 @@ void KDesktopFileTest::testActionGroup()
QTextStream ts(&file);
ts <<
"[Desktop Entry]\n"
"Actions=encrypt;\n"
// make sure escaping of ';' using "\;" works
"Actions=encrypt;semi\\;colon;decrypt;\n"
"[Desktop Action encrypt]\n"
"Name=Encrypt file\n"
"[Desktop Action decrypt]\n"
"Name=Decrypt file\n"
// no escaping needed in group header
"[Desktop Action semi;colon]\n"
"Name=With semicolon\n"
"\n";
file.close();
QVERIFY(QFile::exists(fileName));
KDesktopFile df(fileName);
QCOMPARE(df.readType(), QString());
QCOMPARE(df.fileName(), fileName);
QCOMPARE(df.readActions(), QStringList() << "encrypt");
QCOMPARE(df.readActions(), QStringList() << "encrypt" << "semi;colon" << "decrypt");
QCOMPARE(df.hasActionGroup("encrypt"), true);
QCOMPARE(df.hasActionGroup("semi;colon"), true);
QCOMPARE(df.hasActionGroup("decrypt"), true);
QCOMPARE(df.hasActionGroup("doesnotexist"), false);
KConfigGroup cg = df.actionGroup("encrypt");
QVERIFY(cg.hasKey("Name"));
QCOMPARE(cg.readEntry("Name"), QString("Encrypt file"));
cg = df.actionGroup("decrypt");
QVERIFY(cg.hasKey("Name"));
QCOMPARE(cg.readEntry("Name"), QString("Decrypt file"));
cg = df.actionGroup("semi;colon");
QVERIFY(cg.hasKey("Name"));
QCOMPARE(cg.readEntry("Name"), QString("With semicolon"));
}
void KDesktopFileTest::testIsAuthorizedDesktopFile()

@ -792,6 +792,12 @@ void KConfigIniBackend::printableToString(BufferFragment *aString, const QFile &
case '\\':
*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);

Loading…
Cancel
Save