command: handle string without terminal escaped char

Fixes #2810
This commit is contained in:
Aldo Cortesi 2018-05-12 14:02:20 +12:00
parent 449b8b383d
commit 58ff51da10
2 changed files with 6 additions and 1 deletions

View File

@ -236,7 +236,10 @@ class CommandManager(mitmproxy.types._CommandBase):
"""
Execute a command string. May raise CommandError.
"""
parts = list(lexer(cmdstr))
try:
parts = list(lexer(cmdstr))
except ValueError as e:
raise exceptions.CommandError("Command error: %s" % e)
if not len(parts) >= 1:
raise exceptions.CommandError("Invalid command: %s" % cmdstr)
return self.call_strings(parts[0], parts[1:])

View File

@ -281,6 +281,8 @@ def test_simple():
c.execute("one.two too many args")
with pytest.raises(exceptions.CommandError, match="Unknown"):
c.call("nonexistent")
with pytest.raises(exceptions.CommandError, match="No escaped"):
c.execute("\\")
c.add("empty", a.empty)
c.execute("empty")