mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Correct logic error in EntrySearcher and add more tests
This commit is contained in:
parent
880c3aeb34
commit
340076974e
@ -23,7 +23,7 @@
|
||||
|
||||
EntrySearcher::EntrySearcher(bool caseSensitive)
|
||||
: m_caseSensitive(caseSensitive)
|
||||
, m_termParser(R"re(([-*+]+)?(?:(\w*):)?(?:(?=")"((?:[^"\\]|\\.)*)"|([^ ]*))( |$))re")
|
||||
, m_termParser(R"re(([-!*+]+)?(?:(\w*):)?(?:(?=")"((?:[^"\\]|\\.)*)"|([^ ]*))( |$))re")
|
||||
// Group 1 = modifiers, Group 2 = field, Group 3 = quoted string, Group 4 = unquoted string
|
||||
{
|
||||
}
|
||||
@ -104,7 +104,7 @@ bool EntrySearcher::searchEntryImpl(const QString& searchString, Entry* entry)
|
||||
}
|
||||
|
||||
// Short circuit if we failed to match or we matched and are excluding this term
|
||||
if (!found || term->exclude) {
|
||||
if ((!found && !term->exclude) || (found && term->exclude)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,12 @@
|
||||
|
||||
QTEST_GUILESS_MAIN(TestEntrySearcher)
|
||||
|
||||
void TestEntrySearcher::initTestCase()
|
||||
void TestEntrySearcher::init()
|
||||
{
|
||||
m_rootGroup = new Group();
|
||||
}
|
||||
|
||||
void TestEntrySearcher::cleanupTestCase()
|
||||
void TestEntrySearcher::cleanup()
|
||||
{
|
||||
delete m_rootGroup;
|
||||
}
|
||||
@ -71,6 +71,7 @@ void TestEntrySearcher::testSearch()
|
||||
eRoot2->setNotes("test term test");
|
||||
eRoot2->setGroup(m_rootGroup);
|
||||
|
||||
// Searching is disabled for these
|
||||
Entry* e1 = new Entry();
|
||||
e1->setUsername("test search term test");
|
||||
e1->setGroup(group1);
|
||||
@ -78,6 +79,7 @@ void TestEntrySearcher::testSearch()
|
||||
Entry* e11 = new Entry();
|
||||
e11->setNotes("test search term test");
|
||||
e11->setGroup(group11);
|
||||
// End searching disabled
|
||||
|
||||
Entry* e2111 = new Entry();
|
||||
e2111->setTitle("test search term test");
|
||||
@ -85,6 +87,7 @@ void TestEntrySearcher::testSearch()
|
||||
|
||||
Entry* e2111b = new Entry();
|
||||
e2111b->setNotes("test search test");
|
||||
e2111b->setUsername("user123");
|
||||
e2111b->setPassword("testpass");
|
||||
e2111b->setGroup(group2111);
|
||||
|
||||
@ -94,9 +97,11 @@ void TestEntrySearcher::testSearch()
|
||||
|
||||
Entry* e3b = new Entry();
|
||||
e3b->setTitle("test search test");
|
||||
e3b->setUsername("test@email.com");
|
||||
e3b->setPassword("realpass");
|
||||
e3b->setGroup(group3);
|
||||
|
||||
// Simple search term testing
|
||||
m_searchResult = m_entrySearcher.search("search", m_rootGroup);
|
||||
QCOMPARE(m_searchResult.count(), 5);
|
||||
|
||||
@ -106,9 +111,23 @@ void TestEntrySearcher::testSearch()
|
||||
m_searchResult = m_entrySearcher.search("search term", group211);
|
||||
QCOMPARE(m_searchResult.count(), 1);
|
||||
|
||||
// Test advanced search terms
|
||||
m_searchResult = m_entrySearcher.search("password:testpass", m_rootGroup);
|
||||
QCOMPARE(m_searchResult.count(), 1);
|
||||
|
||||
m_searchResult = m_entrySearcher.search("!user:email.com", m_rootGroup);
|
||||
QCOMPARE(m_searchResult.count(), 5);
|
||||
|
||||
m_searchResult = m_entrySearcher.search("*user:\".*@.*\\.com\"", m_rootGroup);
|
||||
QCOMPARE(m_searchResult.count(), 1);
|
||||
|
||||
m_searchResult = m_entrySearcher.search("+user:email", m_rootGroup);
|
||||
QCOMPARE(m_searchResult.count(), 0);
|
||||
|
||||
// Terms are logical AND together
|
||||
m_searchResult = m_entrySearcher.search("password:pass user:user", m_rootGroup);
|
||||
QCOMPARE(m_searchResult.count(), 1);
|
||||
|
||||
// Parent group has search disabled
|
||||
m_searchResult = m_entrySearcher.search("search term", group11);
|
||||
QCOMPARE(m_searchResult.count(), 0);
|
||||
|
@ -28,8 +28,8 @@ class TestEntrySearcher : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
void testAndConcatenationInSearch();
|
||||
void testSearch();
|
||||
|
Loading…
Reference in New Issue
Block a user