From af14929af1657796e3dc8369442079126ce2ef11 Mon Sep 17 00:00:00 2001 From: Aetf Date: Tue, 17 Dec 2019 16:34:07 -0500 Subject: [PATCH] FdoSecrets: fix searching of entries with special characters in attributes --- src/fdosecrets/objects/Collection.cpp | 3 ++- tests/TestFdoSecrets.cpp | 32 +++++++++++++++++++++++++++ tests/TestFdoSecrets.h | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/fdosecrets/objects/Collection.cpp b/src/fdosecrets/objects/Collection.cpp index b8708aa2..dd407986 100644 --- a/src/fdosecrets/objects/Collection.cpp +++ b/src/fdosecrets/objects/Collection.cpp @@ -30,6 +30,7 @@ #include "gui/DatabaseWidget.h" #include +#include namespace FdoSecrets { @@ -273,7 +274,7 @@ namespace FdoSecrets const auto useWildcards = false; const auto exactMatch = true; const auto caseSensitive = true; - term.regex = Tools::convertToRegex(value, useWildcards, exactMatch, caseSensitive); + term.regex = Tools::convertToRegex(QRegularExpression::escape(value), useWildcards, exactMatch, caseSensitive); return term; } diff --git a/tests/TestFdoSecrets.cpp b/tests/TestFdoSecrets.cpp index 30d8da5c..299c3f7b 100644 --- a/tests/TestFdoSecrets.cpp +++ b/tests/TestFdoSecrets.cpp @@ -112,3 +112,35 @@ void TestFdoSecrets::testCrazyAttributeKey() const auto res = EntrySearcher().search({term}, root.data()); QCOMPARE(res.count(), 1); } + +void TestFdoSecrets::testSpecialCharsInAttributeValue() +{ + using FdoSecrets::Collection; + using FdoSecrets::Item; + + const QScopedPointer root(new Group()); + QScopedPointer e1(new Entry()); + e1->setGroup(root.data()); + + e1->setTitle("titleA"); + e1->attributes()->set("testAttribute", "OAuth::[test.name@gmail.com]"); + + QScopedPointer e2(new Entry()); + e2->setGroup(root.data()); + e2->setTitle("titleB"); + e2->attributes()->set("testAttribute", "Abc:*+.-"); + + // search for custom entries via programatic API + { + const auto term = Collection::attributeToTerm("testAttribute", "OAuth::[test.name@gmail.com]"); + const auto res = EntrySearcher().search({term}, root.data()); + QCOMPARE(res.count(), 1); + QCOMPARE(res[0]->title(), QStringLiteral("titleA")); + } + { + const auto term = Collection::attributeToTerm("testAttribute", "Abc:*+.-"); + const auto res = EntrySearcher().search({term}, root.data()); + QCOMPARE(res.count(), 1); + QCOMPARE(res[0]->title(), QStringLiteral("titleB")); + } +} diff --git a/tests/TestFdoSecrets.h b/tests/TestFdoSecrets.h index e108a81b..1cecbbea 100644 --- a/tests/TestFdoSecrets.h +++ b/tests/TestFdoSecrets.h @@ -31,6 +31,7 @@ private slots: void testGcryptMPI(); void testDhIetf1024Sha256Aes128CbcPkcs7(); void testCrazyAttributeKey(); + void testSpecialCharsInAttributeValue(); }; #endif // KEEPASSXC_TESTFDOSECRETS_H