mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-06-08 15:02:41 -04:00
Whitespace separated search terms are AND concatenated.
This commit is contained in:
parent
4d263a09db
commit
92bf7c94d0
4 changed files with 48 additions and 4 deletions
|
@ -536,10 +536,21 @@ const Database* Entry::database() const
|
||||||
|
|
||||||
bool Entry::match(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity)
|
bool Entry::match(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity)
|
||||||
{
|
{
|
||||||
return title().contains(searchTerm, caseSensitivity) ||
|
QStringList wordList = searchTerm.split(QRegExp("\\s"), QString::SkipEmptyParts);
|
||||||
username().contains(searchTerm, caseSensitivity) ||
|
Q_FOREACH (const QString& word, wordList) {
|
||||||
url().contains(searchTerm, caseSensitivity) ||
|
if (!wordMatch(word, caseSensitivity)) {
|
||||||
notes().contains(searchTerm, 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
|
QString Entry::resolvePlaceholders(const QString& str) const
|
||||||
|
|
|
@ -141,6 +141,7 @@ private Q_SLOTS:
|
||||||
void updateModifiedSinceBegin();
|
void updateModifiedSinceBegin();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool wordMatch(const QString& word, Qt::CaseSensitivity caseSensitivity);
|
||||||
const Database* database() const;
|
const Database* database() const;
|
||||||
template <class T> bool set(T& property, const T& value);
|
template <class T> bool set(T& property, const T& value);
|
||||||
|
|
||||||
|
|
|
@ -399,4 +399,35 @@ void TestGroup::testSearch()
|
||||||
delete groupRoot;
|
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)
|
QTEST_GUILESS_MAIN(TestGroup)
|
||||||
|
|
|
@ -32,6 +32,7 @@ private Q_SLOTS:
|
||||||
void testDeleteSignals();
|
void testDeleteSignals();
|
||||||
void testCopyCustomIcon();
|
void testCopyCustomIcon();
|
||||||
void testSearch();
|
void testSearch();
|
||||||
|
void testAndConcatenationInSearch();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_TESTGROUP_H
|
#endif // KEEPASSX_TESTGROUP_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue