From b867b8795571f20e2f7ed7e9d262971cac79c2f0 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Mon, 12 Sep 2016 12:35:57 -0400 Subject: [PATCH] Don't crash Completer on unknown command. The CommandRunner's fallback parsing behavior treated whitespace differently than the normal flow. When a user entered an unknown command, trailing whitespace would be stripped and the cmdline length would be less than the cursor position. This is fixed by making the fallback use the ShellLexer just as the 'normal' parsing does. --- qutebrowser/commands/runners.py | 13 +++---------- tests/unit/completion/test_completer.py | 1 + 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index 970fbadbe..ea10520dc 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -174,15 +174,6 @@ class CommandRunner(QObject): count = None return (count, cmdstr) - def _parse_fallback(self, text, count, keep): - """Parse the given commandline without a valid command.""" - if keep: - cmdstr, sep, argstr = text.partition(' ') - cmdline = [cmdstr, sep] + argstr.split() - else: - cmdline = text.split() - return ParseResult(cmd=None, args=None, cmdline=cmdline, count=count) - def parse(self, text, *, fallback=False, keep=False): """Split the commandline text into command and arguments. @@ -210,7 +201,9 @@ class CommandRunner(QObject): if not fallback: raise cmdexc.NoSuchCommandError( '{}: no such command'.format(cmdstr)) - return self._parse_fallback(text, count, keep) + cmdline = split.split(text, keep=keep) + return ParseResult(cmd=None, args=None, cmdline=cmdline, + count=count) args = self._split_args(cmd, argstr, keep) if keep and args: diff --git a/tests/unit/completion/test_completer.py b/tests/unit/completion/test_completer.py index 233ba5307..6bc651d4f 100644 --- a/tests/unit/completion/test_completer.py +++ b/tests/unit/completion/test_completer.py @@ -176,6 +176,7 @@ def _set_cmd_prompt(cmd, txt): usertypes.Completion.command)), (':set -t -p |', usertypes.Completion.section), (':open -- |', None), + (':gibberish nonesense |', None), ]) def test_update_completion(txt, expected, status_command_stub, completer_obj, completion_widget_stub):