summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Roden-Corrent <ryan@rcorre.net>2018-01-04 12:27:19 -0500
committerRyan Roden-Corrent <ryan@rcorre.net>2018-01-04 12:34:06 -0500
commitc290b3f80f41b255a5b46480990d692425a6c253 (patch)
tree03ddbb7de3a67089a4056a58046303bed7b919cb
parentc3bcb1d9ba6ab244c2004e2b73fad3de40b77b2d (diff)
downloadqutebrowser-c290b3f80f41b255a5b46480990d692425a6c253.tar.gz
qutebrowser-c290b3f80f41b255a5b46480990d692425a6c253.zip
Don't attempt completion if input starts with flag.
Always interpret the first word in the command string as the command to offer completions for, even if that word looks like a flag. Fixes #3460, where the command string `:-w open` would attempt to offer completions for `open` but crash because the parsing was thrown off. By moving the flag-stripping logic to _after_ we determine the command, `:-w open` interprets `:-w` as the command. Since that is not a valid command, we won't offer any completions.
-rw-r--r--qutebrowser/completion/completer.py5
-rw-r--r--tests/unit/completion/test_completer.py1
2 files changed, 4 insertions, 2 deletions
diff --git a/qutebrowser/completion/completer.py b/qutebrowser/completion/completer.py
index 30a180554..4e187750d 100644
--- a/qutebrowser/completion/completer.py
+++ b/qutebrowser/completion/completer.py
@@ -87,8 +87,6 @@ class Completer(QObject):
# cursor on a flag or after an explicit split (--)
return None
log.completion.debug("Before removing flags: {}".format(before_cursor))
- before_cursor = [x for x in before_cursor if not x.startswith('-')]
- log.completion.debug("After removing flags: {}".format(before_cursor))
if not before_cursor:
# '|' or 'set|'
log.completion.debug('Starting command completion')
@@ -99,6 +97,9 @@ class Completer(QObject):
log.completion.debug("No completion for unknown command: {}"
.format(before_cursor[0]))
return None
+
+ before_cursor = [x for x in before_cursor if not x.startswith('-')]
+ log.completion.debug("After removing flags: {}".format(before_cursor))
argpos = len(before_cursor) - 1
try:
func = cmd.get_pos_arg_info(argpos).completion
diff --git a/tests/unit/completion/test_completer.py b/tests/unit/completion/test_completer.py
index e25d4e5d1..4b39b7032 100644
--- a/tests/unit/completion/test_completer.py
+++ b/tests/unit/completion/test_completer.py
@@ -190,6 +190,7 @@ def _set_cmd_prompt(cmd, txt):
(':gibberish nonesense |', None, '', []),
('/:help|', None, '', []),
('::bind|', 'command', ':bind', []),
+ (':-w open |', None, '', []),
])
def test_update_completion(txt, kind, pattern, pos_args, status_command_stub,
completer_obj, completion_widget_stub, config_stub,