Skip to content

Commit 2a93123

Browse files
Copilotdroidmonkey
andcommitted
Fix confusing behavior when leaving window title empty in Auto-Type
- Modified Entry::autoTypeSequences() to treat empty window titles as catch-all associations - Empty window title associations now match any window instead of being ignored - Added comprehensive test case to verify the new behavior - Fixes issue where empty window title associations only appeared during search Co-authored-by: droidmonkey <[email protected]>
1 parent aedd4ae commit 2a93123

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/core/Entry.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ QList<QString> Entry::autoTypeSequences(const QString& windowTitle) const
339339
const auto assocList = autoTypeAssociations()->getAll();
340340
for (const auto& assoc : assocList) {
341341
auto window = resolveMultiplePlaceholders(assoc.window);
342-
if (!assoc.window.isEmpty() && windowMatches(window)) {
342+
// Empty window title matches any window (acts as default/catch-all)
343+
// Non-empty window title must match the current window
344+
if (assoc.window.isEmpty() || windowMatches(window)) {
343345
if (!assoc.sequence.isEmpty()) {
344346
sequenceList << assoc.sequence;
345347
} else {

tests/TestAutoType.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ void TestAutoType::init()
125125
m_entry5->setPassword("example5");
126126
m_entry5->setTitle("some title");
127127
m_entry5->setUrl("http://example.org");
128+
129+
// Entry with empty window title (should act as default/catch-all)
130+
m_entry6 = new Entry();
131+
m_entry6->setGroup(m_group);
132+
m_entry6->setPassword("empty_window_test");
133+
association.window = ""; // Empty window title
134+
association.sequence = "empty_window_sequence";
135+
m_entry6->autoTypeAssociations()->add(association);
128136
}
129137

130138
void TestAutoType::cleanup()
@@ -280,6 +288,31 @@ void TestAutoType::testGlobalAutoTypeRegExp()
280288
m_test->clearActions();
281289
}
282290

291+
void TestAutoType::testGlobalAutoTypeEmptyWindow()
292+
{
293+
// Test that empty window title associations work as default/catch-all
294+
// This should match any window since the association has an empty window title
295+
m_test->setActiveWindowTitle("any random window title");
296+
emit osUtils->globalShortcutTriggered("autotype");
297+
m_autoType->performGlobalAutoType(m_dbList);
298+
QCOMPARE(m_test->actionChars(), QString("empty_window_sequence"));
299+
m_test->clearActions();
300+
301+
// Test with a different window title - should still match
302+
m_test->setActiveWindowTitle("completely different title");
303+
emit osUtils->globalShortcutTriggered("autotype");
304+
m_autoType->performGlobalAutoType(m_dbList);
305+
QCOMPARE(m_test->actionChars(), QString("empty_window_sequence"));
306+
m_test->clearActions();
307+
308+
// Test with empty window title - should still match
309+
m_test->setActiveWindowTitle("");
310+
emit osUtils->globalShortcutTriggered("autotype");
311+
m_autoType->performGlobalAutoType(m_dbList);
312+
QCOMPARE(m_test->actionChars(), QString("empty_window_sequence"));
313+
m_test->clearActions();
314+
}
315+
283316
void TestAutoType::testAutoTypeResults()
284317
{
285318
QScopedPointer<Entry> entry(new Entry());

tests/TestAutoType.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private slots:
4747
void testGlobalAutoTypeUrlSubdomainMatch();
4848
void testGlobalAutoTypeTitleMatchDisabled();
4949
void testGlobalAutoTypeRegExp();
50+
void testGlobalAutoTypeEmptyWindow();
5051
void testAutoTypeResults();
5152
void testAutoTypeResults_data();
5253
void testAutoTypeSyntaxChecks();
@@ -64,6 +65,7 @@ private slots:
6465
Entry* m_entry3;
6566
Entry* m_entry4;
6667
Entry* m_entry5;
68+
Entry* m_entry6;
6769
};
6870

6971
#endif // KEEPASSX_TESTAUTOTYPE_H

0 commit comments

Comments
 (0)