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:
parent
b31360b6e3
commit
8eab402820
@ -26,7 +26,7 @@ from qutebrowser.keyinput import modeman, modeparsers
|
|||||||
from qutebrowser.commands import cmdexc, cmdutils
|
from qutebrowser.commands import cmdexc, cmdutils
|
||||||
from qutebrowser.misc import cmdhistory, editor
|
from qutebrowser.misc import cmdhistory, editor
|
||||||
from qutebrowser.misc import miscwidgets as misc
|
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):
|
class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
||||||
@ -176,6 +176,10 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
|||||||
ed = editor.ExternalEditor(parent=self)
|
ed = editor.ExternalEditor(parent=self)
|
||||||
|
|
||||||
def callback(text):
|
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)
|
self.set_cmd_text(text)
|
||||||
if run:
|
if run:
|
||||||
self.command_accept()
|
self.command_accept()
|
||||||
|
@ -150,3 +150,16 @@ Feature: Opening external editors
|
|||||||
And I run :edit-command --run
|
And I run :edit-command --run
|
||||||
Then the message "bar" should be shown
|
Then the message "bar" should be shown
|
||||||
And "Leaving mode KeyMode.command (reason: cmd accept)" should be logged
|
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
|
||||||
|
@ -58,3 +58,8 @@ def set_up_editor(quteproc, server, tmpdir, text):
|
|||||||
""".format(text=text)))
|
""".format(text=text)))
|
||||||
editor = json.dumps([sys.executable, str(script), '{}'])
|
editor = json.dumps([sys.executable, str(script), '{}'])
|
||||||
quteproc.set_setting('editor.command', editor)
|
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, "")
|
||||||
|
Loading…
Reference in New Issue
Block a user