From c2472d88f19b78c8a8110d71e83b762322d9565b Mon Sep 17 00:00:00 2001 From: cryzed <cryzed@googlemail.com> Date: Fri, 20 Apr 2018 18:21:55 +0200 Subject: [PATCH 1/5] qute-pass: Escape backslashes, so that they are inserted correctly --- misc/userscripts/qute-pass | 3 +++ 1 file changed, 3 insertions(+) diff --git a/misc/userscripts/qute-pass b/misc/userscripts/qute-pass index 5bab9db93..3312c6cc9 100755 --- a/misc/userscripts/qute-pass +++ b/misc/userscripts/qute-pass @@ -158,6 +158,9 @@ def main(arguments): return ExitCodes.COULD_NOT_MATCH_PASSWORD password = match.group(1) + # Escape backslash so that they are inserted correctly + password = password.replace('\\', '\\\\') + insert_mode = ';; enter-mode insert' if arguments.insert_mode else '' if arguments.username_only: qute_command('fake-key {}{}'.format(username, insert_mode)) From 2de64288300fd2380d0ec1140ba8b6ca6d55d8e1 Mon Sep 17 00:00:00 2001 From: cryzed <cryzed@googlemail.com> Date: Fri, 20 Apr 2018 18:23:50 +0200 Subject: [PATCH 2/5] qute-pass: Also escape backslashes in the username --- misc/userscripts/qute-pass | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/misc/userscripts/qute-pass b/misc/userscripts/qute-pass index 3312c6cc9..4eddaf54c 100755 --- a/misc/userscripts/qute-pass +++ b/misc/userscripts/qute-pass @@ -150,6 +150,7 @@ def main(arguments): stderr('Failed to match username pattern on {}!'.format(arguments.username_target)) return ExitCodes.COULD_NOT_MATCH_USERNAME username = match.group(1) + username = username.replace('\\', '\\\\') # Match password match = re.match(arguments.password_pattern, secret) @@ -157,8 +158,6 @@ def main(arguments): stderr('Failed to match password pattern on secret!') return ExitCodes.COULD_NOT_MATCH_PASSWORD password = match.group(1) - - # Escape backslash so that they are inserted correctly password = password.replace('\\', '\\\\') insert_mode = ';; enter-mode insert' if arguments.insert_mode else '' From 6825dfb8d8706a14980f66ca7b3519a631d08c6f Mon Sep 17 00:00:00 2001 From: cryzed <cryzed@googlemail.com> Date: Mon, 23 Apr 2018 19:01:12 +0200 Subject: [PATCH 3/5] qute-pass: Fake strings letter-by-letter to avoid issues --- misc/userscripts/qute-pass | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/misc/userscripts/qute-pass b/misc/userscripts/qute-pass index 4eddaf54c..fbe49a48a 100755 --- a/misc/userscripts/qute-pass +++ b/misc/userscripts/qute-pass @@ -109,6 +109,11 @@ def dmenu(items, invocation, encoding): return process.stdout.decode(encoding).strip() +def fake_key_raw(text): + for character in text: + qute_command(f'fake-key {character}') + + def main(arguments): if not arguments.url: argument_parser.print_help() @@ -150,7 +155,6 @@ def main(arguments): stderr('Failed to match username pattern on {}!'.format(arguments.username_target)) return ExitCodes.COULD_NOT_MATCH_USERNAME username = match.group(1) - username = username.replace('\\', '\\\\') # Match password match = re.match(arguments.password_pattern, secret) @@ -158,17 +162,20 @@ def main(arguments): stderr('Failed to match password pattern on secret!') return ExitCodes.COULD_NOT_MATCH_PASSWORD password = match.group(1) - password = password.replace('\\', '\\\\') - insert_mode = ';; enter-mode insert' if arguments.insert_mode else '' if arguments.username_only: - qute_command('fake-key {}{}'.format(username, insert_mode)) + fake_key_raw(username) elif arguments.password_only: - qute_command('fake-key {}{}'.format(password, insert_mode)) + fake_key_raw(password) else: # Enter username and password using fake-key and <Tab> (which seems to work almost universally), then switch # back into insert-mode, so the form can be directly submitted by hitting enter afterwards - qute_command('fake-key {} ;; fake-key <Tab> ;; fake-key {}{}'.format(username, password, insert_mode)) + fake_key_raw(username) + qute_command('fake-key <Tab>') + fake_key_raw(password) + + if arguments.insert_mode: + qute_command('enter-mode insert') return ExitCodes.SUCCESS From 92aedf84f57123a42b82d45ff5823abd56729754 Mon Sep 17 00:00:00 2001 From: cryzed <cryzed@googlemail.com> Date: Mon, 23 Apr 2018 19:16:51 +0200 Subject: [PATCH 4/5] qute-pass: Don't use f-strings --- misc/userscripts/qute-pass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/userscripts/qute-pass b/misc/userscripts/qute-pass index fbe49a48a..fc897be07 100755 --- a/misc/userscripts/qute-pass +++ b/misc/userscripts/qute-pass @@ -111,7 +111,7 @@ def dmenu(items, invocation, encoding): def fake_key_raw(text): for character in text: - qute_command(f'fake-key {character}') + qute_command('fake-key {}'.format(character)) def main(arguments): From 801e9e0334dcc58cbe52b936951d93c1e3c1e3c7 Mon Sep 17 00:00:00 2001 From: cryzed <cryzed@googlemail.com> Date: Sun, 29 Apr 2018 15:22:52 +0200 Subject: [PATCH 5/5] qute-pass: Improve fake_key_raw() --- misc/userscripts/qute-pass | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/misc/userscripts/qute-pass b/misc/userscripts/qute-pass index fc897be07..892f9c5da 100755 --- a/misc/userscripts/qute-pass +++ b/misc/userscripts/qute-pass @@ -111,7 +111,9 @@ def dmenu(items, invocation, encoding): def fake_key_raw(text): for character in text: - qute_command('fake-key {}'.format(character)) + # Escape all characters by default, space requires special handling + sequence = '" "' if character == ' ' else '\{}'.format(character) + qute_command('fake-key {}'.format(sequence)) def main(arguments):