Abort :edit-command on invalid input.

Show an error message if the user edits the command such that it is
missing a start character (:, /, or ?). Previously, this would cause the
browser to crash.

Resolves #3326.
This commit is contained in:
Ryan Roden-Corrent 2017-11-23 08:07:11 -05:00
parent b31360b6e3
commit 8eab402820
3 changed files with 23 additions and 1 deletions

View File

@ -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()

View File

@ -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

View File

@ -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, "")