diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2018-05-12 14:02:20 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2018-05-12 14:02:20 +1200 |
commit | 58ff51da10eff7090ff2a63436c558b1eb5150c3 (patch) | |
tree | b52abd8afbf7e56ff32a67b876617fa68c302042 | |
parent | 449b8b383deb8ba631bd708333c93638931d77db (diff) | |
download | mitmproxy-58ff51da10eff7090ff2a63436c558b1eb5150c3.tar.gz mitmproxy-58ff51da10eff7090ff2a63436c558b1eb5150c3.tar.bz2 mitmproxy-58ff51da10eff7090ff2a63436c558b1eb5150c3.zip |
command: handle string without terminal escaped char
Fixes #2810
-rw-r--r-- | mitmproxy/command.py | 5 | ||||
-rw-r--r-- | test/mitmproxy/test_command.py | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/mitmproxy/command.py b/mitmproxy/command.py index c94e8abb..27f0921d 100644 --- a/mitmproxy/command.py +++ b/mitmproxy/command.py @@ -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:]) diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index 7c0dc06d..029dbafd 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -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") |