aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2018-02-23 13:32:44 +1300
committerGitHub <noreply@github.com>2018-02-23 13:32:44 +1300
commit06807414c15c32020f48c5b5b63f4ffc58c7b33d (patch)
tree4c468049153735dca4349764a126e3e7977d2472
parent58ccad7576e5fd33e937aba58df2f9edc389e52e (diff)
parentc471c42c7c2b26b4330c7780abe72cc8176580ab (diff)
downloadmitmproxy-06807414c15c32020f48c5b5b63f4ffc58c7b33d.tar.gz
mitmproxy-06807414c15c32020f48c5b5b63f4ffc58c7b33d.tar.bz2
mitmproxy-06807414c15c32020f48c5b5b63f4ffc58c7b33d.zip
Merge pull request #2896 from cortesi/cmdesc
Fix an issue with quoting and commands
-rw-r--r--mitmproxy/tools/console/commander/commander.py22
-rw-r--r--test/mitmproxy/test_command.py16
2 files changed, 35 insertions, 3 deletions
diff --git a/mitmproxy/tools/console/commander/commander.py b/mitmproxy/tools/console/commander/commander.py
index 566c42e6..f3e499f8 100644
--- a/mitmproxy/tools/console/commander/commander.py
+++ b/mitmproxy/tools/console/commander/commander.py
@@ -68,6 +68,21 @@ class CommandBuffer:
else:
self._cursor = x
+ def maybequote(self, value):
+ if " " in value and not value.startswith("\""):
+ return "\"%s\"" % value
+ return value
+
+ def parse_quoted(self, txt):
+ parts, remhelp = self.master.commands.parse_partial(txt)
+ for i, p in enumerate(parts):
+ parts[i] = mitmproxy.command.ParseResult(
+ value = self.maybequote(p.value),
+ type = p.type,
+ valid = p.valid
+ )
+ return parts, remhelp
+
def render(self):
"""
This function is somewhat tricky - in order to make the cursor
@@ -75,7 +90,7 @@ class CommandBuffer:
character-for-character offset match in the rendered output, up
to the cursor. Beyond that, we can add stuff.
"""
- parts, remhelp = self.master.commands.parse_partial(self.text)
+ parts, remhelp = self.parse_quoted(self.text)
ret = []
for p in parts:
if p.valid:
@@ -95,8 +110,9 @@ class CommandBuffer:
return ret
def flatten(self, txt):
- parts, _ = self.master.commands.parse_partial(txt)
- return " ".join([x.value for x in parts])
+ parts, _ = self.parse_quoted(txt)
+ ret = [x.value for x in parts]
+ return " ".join(ret)
def left(self) -> None:
self.cursor = self.cursor - 1
diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py
index c777192d..e2b80753 100644
--- a/test/mitmproxy/test_command.py
+++ b/test/mitmproxy/test_command.py
@@ -211,6 +211,22 @@ class TestCommand:
],
[]
],
+ [
+ "flow \"one two",
+ [
+ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True),
+ command.ParseResult(value = "\"one two", type = flow.Flow, valid = False),
+ ],
+ ["str"]
+ ],
+ [
+ "flow \"one two\"",
+ [
+ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True),
+ command.ParseResult(value = "one two", type = flow.Flow, valid = False),
+ ],
+ ["str"]
+ ],
]
with taddons.context() as tctx:
tctx.master.addons.add(TAddon())