FdoSecrets: fix searching of entries with special characters in attributes

This commit is contained in:
Aetf 2019-12-17 16:34:07 -05:00 committed by Jonathan White
parent 3ffeab4c41
commit af14929af1
3 changed files with 35 additions and 1 deletions

View File

@ -30,6 +30,7 @@
#include "gui/DatabaseWidget.h"
#include <QFileInfo>
#include <QRegularExpression>
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;
}

View File

@ -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<Group> root(new Group());
QScopedPointer<Entry> e1(new Entry());
e1->setGroup(root.data());
e1->setTitle("titleA");
e1->attributes()->set("testAttribute", "OAuth::[test.name@gmail.com]");
QScopedPointer<Entry> 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"));
}
}

View File

@ -31,6 +31,7 @@ private slots:
void testGcryptMPI();
void testDhIetf1024Sha256Aes128CbcPkcs7();
void testCrazyAttributeKey();
void testSpecialCharsInAttributeValue();
};
#endif // KEEPASSXC_TESTFDOSECRETS_H