From ae51450ea64970dcdc544185d68e1e73fb390caa Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Tue, 1 Jul 2014 20:33:41 +0200 Subject: 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 --- autotests/kconfigtest.cpp | 27 +++++++++++++++++++++++++++ autotests/kconfigtest.h | 1 + autotests/kdesktopfiletest.cpp | 18 ++++++++++++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) (limited to 'autotests') diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp index 5f2c7989..7cb3f903 100644 --- a/autotests/kconfigtest.cpp +++ b/autotests/kconfigtest.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 #include diff --git a/autotests/kconfigtest.h b/autotests/kconfigtest.h index f2897a8f..be0a17ea 100644 --- a/autotests/kconfigtest.h +++ b/autotests/kconfigtest.h @@ -76,6 +76,7 @@ private Q_SLOTS: void testDirtyAfterRevert(); void testKdeGlobals(); void testNewlines(); + void testXdgListEntry(); void testThreads(); diff --git a/autotests/kdesktopfiletest.cpp b/autotests/kdesktopfiletest.cpp index b1938b80..3ee291f4 100644 --- a/autotests/kdesktopfiletest.cpp +++ b/autotests/kdesktopfiletest.cpp @@ -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() -- cgit v1.2.1