diff --git a/src/core/EntrySearcher.cpp b/src/core/EntrySearcher.cpp index 3292ca112d..4a25eaf71b 100644 --- a/src/core/EntrySearcher.cpp +++ b/src/core/EntrySearcher.cpp @@ -218,6 +218,9 @@ bool EntrySearcher::searchEntryImpl(const Entry* entry) } found = false; break; + case Field::Uuid: + found = term.regex.match(entry->uuidToHex()).hasMatch(); + break; default: // Terms without a specific field try to match title, username, url, and notes found = term.regex.match(entry->resolvePlaceholder(entry->title())).hasMatch() @@ -253,7 +256,8 @@ void EntrySearcher::parseSearchTerms(const QString& searchString) {QStringLiteral("url"), Field::Url}, {QStringLiteral("group"), Field::Group}, {QStringLiteral("tag"), Field::Tag}, - {QStringLiteral("is"), Field::Is}}; + {QStringLiteral("is"), Field::Is}, + {QStringLiteral("uuid"), Field::Uuid}}; // Group 1 = modifiers, Group 2 = field, Group 3 = quoted string, Group 4 = unquoted string static QRegularExpression termParser(R"re(([-!*+]+)?(?:(\w*):)?(?:(?=")"((?:[^"\\]|\\.)*)"|([^ ]*))( |$))re"); diff --git a/src/core/EntrySearcher.h b/src/core/EntrySearcher.h index 9376d10de1..0134054bf5 100644 --- a/src/core/EntrySearcher.h +++ b/src/core/EntrySearcher.h @@ -40,7 +40,8 @@ class EntrySearcher AttributeValue, Group, Tag, - Is + Is, + Uuid }; struct SearchTerm diff --git a/src/gui/SearchHelpWidget.ui b/src/gui/SearchHelpWidget.ui index bd8731eb9f..907b2822d9 100644 --- a/src/gui/SearchHelpWidget.ui +++ b/src/gui/SearchHelpWidget.ui @@ -214,6 +214,13 @@ + + + + uuid + + + diff --git a/tests/TestEntrySearcher.cpp b/tests/TestEntrySearcher.cpp index 4729fb446a..09d06cd316 100644 --- a/tests/TestEntrySearcher.cpp +++ b/tests/TestEntrySearcher.cpp @@ -17,6 +17,7 @@ #include "TestEntrySearcher.h" #include "core/Group.h" +#include "core/Tools.h" #include @@ -372,3 +373,24 @@ void TestEntrySearcher::testSkipProtected() m_entrySearcher.search("_testAttribute:testE1 _testProtected:apple _testAttribute:testE2", m_rootGroup); QCOMPARE(m_searchResult, {}); } + +void TestEntrySearcher::testUUIDSearch() +{ + auto entry1 = new Entry(); + entry1->setGroup(m_rootGroup); + entry1->setTitle("testTitle"); + auto uuid1 = QUuid::createUuid(); + entry1->setUuid(uuid1); + + auto entry2 = new Entry(); + entry2->setGroup(m_rootGroup); + entry2->setTitle("testTitle2"); + auto uuid2 = QUuid::createUuid(); + entry2->setUuid(uuid2); + + m_searchResult = m_entrySearcher.search("uuid:", m_rootGroup); + QCOMPARE(m_searchResult.count(), 2); + + m_searchResult = m_entrySearcher.search("uuid:" + Tools::uuidToHex(uuid1), m_rootGroup); + QCOMPARE(m_searchResult.count(), 1); +} diff --git a/tests/TestEntrySearcher.h b/tests/TestEntrySearcher.h index becd5f20de..2ca81a7429 100644 --- a/tests/TestEntrySearcher.h +++ b/tests/TestEntrySearcher.h @@ -38,6 +38,7 @@ private slots: void testCustomAttributesAreSearched(); void testGroup(); void testSkipProtected(); + void testUUIDSearch(); private: Group* m_rootGroup;