Skip to content

Commit

Permalink
Add uuid search (keepassxreboot#9571)
Browse files Browse the repository at this point in the history
Co-authored-by: lukas <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 4, 2023
1 parent 8ab6bad commit 6fab98e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/core/EntrySearcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/core/EntrySearcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class EntrySearcher
AttributeValue,
Group,
Tag,
Is
Is,
Uuid
};

struct SearchTerm
Expand Down
7 changes: 7 additions & 0 deletions src/gui/SearchHelpWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string notr="true">uuid</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_5">
<property name="text">
Expand Down
22 changes: 22 additions & 0 deletions tests/TestEntrySearcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "TestEntrySearcher.h"
#include "core/Group.h"
#include "core/Tools.h"

#include <QTest>

Expand Down Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions tests/TestEntrySearcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private slots:
void testCustomAttributesAreSearched();
void testGroup();
void testSkipProtected();
void testUUIDSearch();

private:
Group* m_rootGroup;
Expand Down

0 comments on commit 6fab98e

Please sign in to comment.