mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-07 05:52:33 -04:00
Auto-Type: Only require a substring match for regex.
This matches the behavior of KeePass. Refs #357
This commit is contained in:
parent
862941abf6
commit
820941fd40
3 changed files with 45 additions and 3 deletions
|
@ -575,7 +575,7 @@ bool AutoType::windowMatches(const QString& windowTitle, const QString& windowPa
|
||||||
{
|
{
|
||||||
if (windowPattern.startsWith("//") && windowPattern.endsWith("//") && windowPattern.size() >= 4) {
|
if (windowPattern.startsWith("//") && windowPattern.endsWith("//") && windowPattern.size() >= 4) {
|
||||||
QRegExp regExp(windowPattern.mid(2, windowPattern.size() - 4), Qt::CaseInsensitive, QRegExp::RegExp2);
|
QRegExp regExp(windowPattern.mid(2, windowPattern.size() - 4), Qt::CaseInsensitive, QRegExp::RegExp2);
|
||||||
return regExp.exactMatch(windowTitle);
|
return (regExp.indexIn(windowTitle) != -1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return WildcardMatcher(windowTitle).match(windowPattern);
|
return WildcardMatcher(windowTitle).match(windowPattern);
|
||||||
|
|
|
@ -64,11 +64,12 @@ void TestAutoType::init()
|
||||||
m_group = new Group();
|
m_group = new Group();
|
||||||
m_db->setRootGroup(m_group);
|
m_db->setRootGroup(m_group);
|
||||||
|
|
||||||
|
AutoTypeAssociations::Association association;
|
||||||
|
|
||||||
m_entry1 = new Entry();
|
m_entry1 = new Entry();
|
||||||
m_entry1->setGroup(m_group);
|
m_entry1->setGroup(m_group);
|
||||||
m_entry1->setUsername("myuser");
|
m_entry1->setUsername("myuser");
|
||||||
m_entry1->setPassword("mypass");
|
m_entry1->setPassword("mypass");
|
||||||
AutoTypeAssociations::Association association;
|
|
||||||
association.window = "custom window";
|
association.window = "custom window";
|
||||||
association.sequence = "{username}association{password}";
|
association.sequence = "{username}association{password}";
|
||||||
m_entry1->autoTypeAssociations()->add(association);
|
m_entry1->autoTypeAssociations()->add(association);
|
||||||
|
@ -77,6 +78,19 @@ void TestAutoType::init()
|
||||||
m_entry2->setGroup(m_group);
|
m_entry2->setGroup(m_group);
|
||||||
m_entry2->setPassword("myuser");
|
m_entry2->setPassword("myuser");
|
||||||
m_entry2->setTitle("entry title");
|
m_entry2->setTitle("entry title");
|
||||||
|
|
||||||
|
m_entry3 = new Entry();
|
||||||
|
m_entry3->setGroup(m_group);
|
||||||
|
m_entry3->setPassword("regex");
|
||||||
|
association.window = "//REGEX1//";
|
||||||
|
association.sequence = "regex1";
|
||||||
|
m_entry3->autoTypeAssociations()->add(association);
|
||||||
|
association.window = "//^REGEX2$//";
|
||||||
|
association.sequence = "regex2";
|
||||||
|
m_entry3->autoTypeAssociations()->add(association);
|
||||||
|
association.window = "//^REGEX3-([rd]\\d){2}$//";
|
||||||
|
association.sequence = "regex3";
|
||||||
|
m_entry3->autoTypeAssociations()->add(association);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestAutoType::cleanup()
|
void TestAutoType::cleanup()
|
||||||
|
@ -152,5 +166,31 @@ void TestAutoType::testGlobalAutoTypeTitleMatchDisabled()
|
||||||
m_autoType->performGlobalAutoType(m_dbList);
|
m_autoType->performGlobalAutoType(m_dbList);
|
||||||
|
|
||||||
QCOMPARE(m_test->actionChars(), QString());
|
QCOMPARE(m_test->actionChars(), QString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestAutoType::testGlobalAutoTypeRegExp()
|
||||||
|
{
|
||||||
|
// substring matches are ok
|
||||||
|
m_test->setActiveWindowTitle("lorem REGEX1 ipsum");
|
||||||
|
m_autoType->performGlobalAutoType(m_dbList);
|
||||||
|
QCOMPARE(m_test->actionChars(), QString("regex1"));
|
||||||
|
m_test->clearActions();
|
||||||
|
|
||||||
|
// should be case-insensitive
|
||||||
|
m_test->setActiveWindowTitle("lorem regex1 ipsum");
|
||||||
|
m_autoType->performGlobalAutoType(m_dbList);
|
||||||
|
QCOMPARE(m_test->actionChars(), QString("regex1"));
|
||||||
|
m_test->clearActions();
|
||||||
|
|
||||||
|
// exact match
|
||||||
|
m_test->setActiveWindowTitle("REGEX2");
|
||||||
|
m_autoType->performGlobalAutoType(m_dbList);
|
||||||
|
QCOMPARE(m_test->actionChars(), QString("regex2"));
|
||||||
|
m_test->clearActions();
|
||||||
|
|
||||||
|
// a bit more complicated regex
|
||||||
|
m_test->setActiveWindowTitle("REGEX3-R2D2");
|
||||||
|
m_autoType->performGlobalAutoType(m_dbList);
|
||||||
|
QCOMPARE(m_test->actionChars(), QString("regex3"));
|
||||||
|
m_test->clearActions();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ private Q_SLOTS:
|
||||||
void testGlobalAutoTypeWithOneMatch();
|
void testGlobalAutoTypeWithOneMatch();
|
||||||
void testGlobalAutoTypeTitleMatch();
|
void testGlobalAutoTypeTitleMatch();
|
||||||
void testGlobalAutoTypeTitleMatchDisabled();
|
void testGlobalAutoTypeTitleMatchDisabled();
|
||||||
|
void testGlobalAutoTypeRegExp();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AutoTypePlatformInterface* m_platform;
|
AutoTypePlatformInterface* m_platform;
|
||||||
|
@ -53,6 +54,7 @@ private:
|
||||||
Group* m_group;
|
Group* m_group;
|
||||||
Entry* m_entry1;
|
Entry* m_entry1;
|
||||||
Entry* m_entry2;
|
Entry* m_entry2;
|
||||||
|
Entry* m_entry3;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_TESTAUTOTYPE_H
|
#endif // KEEPASSX_TESTAUTOTYPE_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue