Skip to content

Commit

Permalink
FdoSecrets: fix searching of entries with special characters in attri…
Browse files Browse the repository at this point in the history
…butes
  • Loading branch information
Aetf committed Dec 28, 2019
1 parent 90cdfc4 commit 134eb0f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/fdosecrets/objects/Collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "gui/DatabaseWidget.h"

#include <QFileInfo>
#include <QRegularExpression>

namespace FdoSecrets
{
Expand Down Expand Up @@ -268,7 +269,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;
}
Expand Down
32 changes: 32 additions & 0 deletions tests/TestFdoSecrets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
1 change: 1 addition & 0 deletions tests/TestFdoSecrets.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private slots:
void testGcryptMPI();
void testDhIetf1024Sha256Aes128CbcPkcs7();
void testCrazyAttributeKey();
void testSpecialCharsInAttributeValue();
};

#endif // KEEPASSXC_TESTFDOSECRETS_H

0 comments on commit 134eb0f

Please sign in to comment.