diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index bba2559ed..affb1a23b 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -26,7 +26,7 @@ from qutebrowser.keyinput import modeman, modeparsers from qutebrowser.commands import cmdexc, cmdutils from qutebrowser.misc import cmdhistory, editor from qutebrowser.misc import miscwidgets as misc -from qutebrowser.utils import usertypes, log, objreg +from qutebrowser.utils import usertypes, log, objreg, message class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): @@ -176,6 +176,10 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): ed = editor.ExternalEditor(parent=self) def callback(text): + if not text or text[0] not in modeparsers.STARTCHARS: + message.error('command must start with one of {}' + .format(modeparsers.STARTCHARS)) + return self.set_cmd_text(text) if run: self.command_accept() diff --git a/tests/end2end/features/editor.feature b/tests/end2end/features/editor.feature index 79f4f17d4..93b61df30 100644 --- a/tests/end2end/features/editor.feature +++ b/tests/end2end/features/editor.feature @@ -150,3 +150,16 @@ Feature: Opening external editors And I run :edit-command --run Then the message "bar" should be shown And "Leaving mode KeyMode.command (reason: cmd accept)" should be logged + + Scenario: Edit a command and omit the start char + When I set up a fake editor returning "message-info foo" + And I run :edit-command + Then the error "command must start with one of :/?" should be shown + And "Leaving mode KeyMode.command *" should not be logged + + Scenario: Edit a command to be empty + When I run :set-cmd-text : + When I set up a fake editor returning empty text + And I run :edit-command + Then the error "command must start with one of :/?" should be shown + And "Leaving mode KeyMode.command *" should not be logged diff --git a/tests/end2end/features/test_editor_bdd.py b/tests/end2end/features/test_editor_bdd.py index eb937e0f2..3133bea40 100644 --- a/tests/end2end/features/test_editor_bdd.py +++ b/tests/end2end/features/test_editor_bdd.py @@ -58,3 +58,8 @@ def set_up_editor(quteproc, server, tmpdir, text): """.format(text=text))) editor = json.dumps([sys.executable, str(script), '{}']) quteproc.set_setting('editor.command', editor) + +@bdd.when(bdd.parsers.parse('I set up a fake editor returning empty text')) +def set_up_editor_empty(quteproc, server, tmpdir): + """Set up editor.command to a small python script inserting empty text.""" + set_up_editor(quteproc, server, tmpdir, "")