quote argument of view.flows.resolve (#4910)

* Fix #4902

* Update type signature

* Switch to None check

* Fix spacing

* Quote view.flows.resolve argument

* Switch to call_strings
This commit is contained in:
shindexro 2021-11-19 12:04:20 +00:00 committed by GitHub
parent 7be646f44a
commit 9a469806eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -369,7 +369,7 @@ class _FlowType(_BaseFlowType):
def parse(self, manager: "CommandManager", t: type, s: str) -> flow.Flow:
try:
flows = manager.execute("view.flows.resolve %s" % (s))
flows = manager.call_strings("view.flows.resolve", [s])
except exceptions.CommandError as e:
raise exceptions.TypeError(str(e)) from e
if len(flows) != 1:
@ -388,7 +388,7 @@ class _FlowsType(_BaseFlowType):
def parse(self, manager: "CommandManager", t: type, s: str) -> typing.Sequence[flow.Flow]:
try:
return manager.execute("view.flows.resolve %s" % (s))
return manager.call_strings("view.flows.resolve", [s])
except exceptions.CommandError as e:
raise exceptions.TypeError(str(e)) from e

View File

@ -183,7 +183,10 @@ class DummyConsole:
def resolve(self, spec: str) -> typing.Sequence[flow.Flow]:
if spec == "err":
raise mitmproxy.exceptions.CommandError()
n = int(spec)
try:
n = int(spec)
except ValueError:
n = 1
return [tflow.tflow(resp=True)] * n
@command.command("cut")
@ -201,6 +204,7 @@ def test_flow():
b = mitmproxy.types._FlowType()
assert len(b.completion(tctx.master.commands, flow.Flow, "")) == len(b.valid_prefixes)
assert b.parse(tctx.master.commands, flow.Flow, "1")
assert b.parse(tctx.master.commands, flow.Flow, "has space")
assert b.is_valid(tctx.master.commands, flow.Flow, tflow.tflow()) is True
assert b.is_valid(tctx.master.commands, flow.Flow, "xx") is False
with pytest.raises(mitmproxy.exceptions.TypeError):
@ -224,6 +228,7 @@ def test_flows():
assert len(b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "0")) == 0
assert len(b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "1")) == 1
assert len(b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "2")) == 2
assert len(b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "has space")) == 1
with pytest.raises(mitmproxy.exceptions.TypeError):
b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "err")