mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Whitespace separated search terms are AND concatenated.
This commit is contained in:
parent
4d263a09db
commit
92bf7c94d0
@ -536,10 +536,21 @@ const Database* Entry::database() const
|
||||
|
||||
bool Entry::match(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity)
|
||||
{
|
||||
return title().contains(searchTerm, caseSensitivity) ||
|
||||
username().contains(searchTerm, caseSensitivity) ||
|
||||
url().contains(searchTerm, caseSensitivity) ||
|
||||
notes().contains(searchTerm, caseSensitivity);
|
||||
QStringList wordList = searchTerm.split(QRegExp("\\s"), QString::SkipEmptyParts);
|
||||
Q_FOREACH (const QString& word, wordList) {
|
||||
if (!wordMatch(word, caseSensitivity)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Entry::wordMatch(const QString& word, Qt::CaseSensitivity caseSensitivity)
|
||||
{
|
||||
return title().contains(word, caseSensitivity) ||
|
||||
username().contains(word, caseSensitivity) ||
|
||||
url().contains(word, caseSensitivity) ||
|
||||
notes().contains(word, caseSensitivity);
|
||||
}
|
||||
|
||||
QString Entry::resolvePlaceholders(const QString& str) const
|
||||
|
@ -141,6 +141,7 @@ private Q_SLOTS:
|
||||
void updateModifiedSinceBegin();
|
||||
|
||||
private:
|
||||
bool wordMatch(const QString& word, Qt::CaseSensitivity caseSensitivity);
|
||||
const Database* database() const;
|
||||
template <class T> bool set(T& property, const T& value);
|
||||
|
||||
|
@ -399,4 +399,35 @@ void TestGroup::testSearch()
|
||||
delete groupRoot;
|
||||
}
|
||||
|
||||
void TestGroup::testAndConcatenationInSearch()
|
||||
{
|
||||
Group* group = new Group();
|
||||
Entry* entry = new Entry();
|
||||
entry->setNotes("abc def ghi");
|
||||
entry->setTitle("jkl");
|
||||
entry->setGroup(group);
|
||||
|
||||
QList<Entry*> searchResult;
|
||||
|
||||
searchResult = group->search("", Qt::CaseInsensitive);
|
||||
QCOMPARE(searchResult.count(), 1);
|
||||
|
||||
searchResult = group->search("def", Qt::CaseInsensitive);
|
||||
QCOMPARE(searchResult.count(), 1);
|
||||
|
||||
searchResult = group->search(" abc ghi ", Qt::CaseInsensitive);
|
||||
QCOMPARE(searchResult.count(), 1);
|
||||
|
||||
searchResult = group->search("ghi ef", Qt::CaseInsensitive);
|
||||
QCOMPARE(searchResult.count(), 1);
|
||||
|
||||
searchResult = group->search("abc ef xyz", Qt::CaseInsensitive);
|
||||
QCOMPARE(searchResult.count(), 0);
|
||||
|
||||
searchResult = group->search("abc kl", Qt::CaseInsensitive);
|
||||
QCOMPARE(searchResult.count(), 1);
|
||||
|
||||
delete group;
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestGroup)
|
||||
|
@ -32,6 +32,7 @@ private Q_SLOTS:
|
||||
void testDeleteSignals();
|
||||
void testCopyCustomIcon();
|
||||
void testSearch();
|
||||
void testAndConcatenationInSearch();
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_TESTGROUP_H
|
||||
|
Loading…
Reference in New Issue
Block a user