Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uuid search #9571

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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