0
0
mirror of https://github.com/keepassxreboot/keepassxc.git synced 2024-09-20 04:12:15 +02:00

Auto-Type: PICKCHARS can specify attribute and ignore BEEP

* Fix #7726 - Ignore BEEP Auto-Type token when it includes spaces and numbers as well
* Close #8103 - Allow specifying specific attribute to use with PICKCHARS. If none specified, it defaults to Password.
This commit is contained in:
Jonathan White 2022-06-05 21:56:48 -04:00
parent b1f4e12d34
commit 20a2a96222
3 changed files with 24 additions and 7 deletions

View File

@ -644,6 +644,10 @@
<source>Invalid placeholder: %1</source> <source>Invalid placeholder: %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Entry does not have attribute for PICKCHARS: %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>AutoTypeAssociationsModel</name> <name>AutoTypeAssociationsModel</name>

View File

@ -647,13 +647,26 @@ AutoType::parseSequence(const QString& entrySequence, const Entry* entry, QStrin
for (const auto& ch : totp) { for (const auto& ch : totp) {
actions << QSharedPointer<AutoTypeKey>::create(ch); actions << QSharedPointer<AutoTypeKey>::create(ch);
} }
} else if (placeholder == "pickchars") { } else if (placeholder.startsWith("pickchars")) {
// Ignore this if we are syntax checking // Reset to the original capture to preserve case
placeholder = match.captured(3);
auto attribute = EntryAttributes::PasswordKey;
if (placeholder.contains(":")) {
attribute = placeholder.section(":", 1);
if (!entry->attributes()->hasKey(attribute)) {
error = tr("Entry does not have attribute for PICKCHARS: %1").arg(attribute);
return {};
}
}
// Bail out if we are just syntax checking
if (syntaxOnly) { if (syntaxOnly) {
continue; continue;
} }
// Show pickchars dialog for entry's password
auto password = entry->resolvePlaceholder(entry->password()); // Show pickchars dialog for the desired attribute
auto password = entry->resolvePlaceholder(entry->attribute(attribute));
if (!password.isEmpty()) { if (!password.isEmpty()) {
PickcharsDialog pickcharsDialog(password); PickcharsDialog pickcharsDialog(password);
if (pickcharsDialog.exec() == QDialog::Accepted && !pickcharsDialog.selectedChars().isEmpty()) { if (pickcharsDialog.exec() == QDialog::Accepted && !pickcharsDialog.selectedChars().isEmpty()) {
@ -746,8 +759,8 @@ AutoType::parseSequence(const QString& entrySequence, const Entry* entry, QStrin
mode = AutoTypeExecutor::Mode::VIRTUAL; mode = AutoTypeExecutor::Mode::VIRTUAL;
} }
actions << QSharedPointer<AutoTypeMode>::create(mode); actions << QSharedPointer<AutoTypeMode>::create(mode);
} else if (placeholder == "beep" || placeholder.startsWith("vkey") || placeholder.startsWith("appactivate") } else if (placeholder.startsWith("beep") || placeholder.startsWith("vkey")
|| placeholder.startsWith("c:")) { || placeholder.startsWith("appactivate") || placeholder.startsWith("c:")) {
// Ignore these commands // Ignore these commands
} else { } else {
// Attempt to resolve an entry attribute // Attempt to resolve an entry attribute

View File

@ -337,7 +337,7 @@ void TestAutoType::testAutoTypeSyntaxChecks()
QVERIFY2(AutoType::verifyAutoTypeSyntax("{S:FOO}{S:HELLO WORLD}", entry, error), error.toLatin1()); QVERIFY2(AutoType::verifyAutoTypeSyntax("{S:FOO}{S:HELLO WORLD}", entry, error), error.toLatin1());
QVERIFY2(!AutoType::verifyAutoTypeSyntax("{S:SPECIAL_TOKEN{}}", entry, error), error.toLatin1()); QVERIFY2(!AutoType::verifyAutoTypeSyntax("{S:SPECIAL_TOKEN{}}", entry, error), error.toLatin1());
QVERIFY2(!AutoType::verifyAutoTypeSyntax("{BEEP 3 3}", entry, error), error.toLatin1()); QVERIFY2(AutoType::verifyAutoTypeSyntax("{BEEP 3 3}", entry, error), error.toLatin1());
QVERIFY2(AutoType::verifyAutoTypeSyntax("{BEEP 3}", entry, error), error.toLatin1()); QVERIFY2(AutoType::verifyAutoTypeSyntax("{BEEP 3}", entry, error), error.toLatin1());
QVERIFY2(AutoType::verifyAutoTypeSyntax("{VKEY 0x01}", entry, error), error.toLatin1()); QVERIFY2(AutoType::verifyAutoTypeSyntax("{VKEY 0x01}", entry, error), error.toLatin1());