mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-28 08:49:42 -05:00
FdoSecrets: fix searching of entries with special characters in attributes
This commit is contained in:
parent
3ffeab4c41
commit
af14929af1
@ -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;
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ private slots:
|
||||
void testGcryptMPI();
|
||||
void testDhIetf1024Sha256Aes128CbcPkcs7();
|
||||
void testCrazyAttributeKey();
|
||||
void testSpecialCharsInAttributeValue();
|
||||
};
|
||||
|
||||
#endif // KEEPASSXC_TESTFDOSECRETS_H
|
||||
|
Loading…
Reference in New Issue
Block a user