Repository: mitmproxy/mitmproxy
Pull request: Quote argument of view.flows.resolve
#### Description

Fix #4899.
Quote the argument of internal `view.flows.resolve` calls.

Not sure what is an effective way to test it. The internal `view.flows.resolve` happens after the user invokes `:view.flows.remove ...` Should the test be written in `test_view.py`, `test_types.py` or `test_integration.py`?

#### Checklist

 - [x] I have updated tests where applicable.


Problem statement:
Command argument mismatch when executing command:  ":view.flows.remove '~m POST'"
I am trying to delete all the POST flows.

I execute the command

`:view.flows.remove '~m POST'`

And get the following error

```
error: Command argument mismatch:
    Expected: OrderedDict([('flow_spec', <Parameter "flow_spec: str">)])
    Received: ['~m', 'POST']
```

Filtering the flows via `f` keybind works

#### System Information
Mitmproxy: 7.0.4
Python:    3.9.7
OpenSSL:   OpenSSL 1.1.1l  24 Aug 2021
Platform:  macOS-11.6-x86_64-i386-64bit

Hints from issue discussion:

Commit message: Quote view.flows.resolve argument

Patch to review:
diff --git a/mitmproxy/types.py b/mitmproxy/types.py
index 01d7ac47f8..03391ce982 100644
--- a/mitmproxy/types.py
+++ b/mitmproxy/types.py
@@ -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.execute("view.flows.resolve '%s'" % (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.execute("view.flows.resolve '%s'" % (s))
         except exceptions.CommandError as e:
             raise exceptions.TypeError(str(e)) from e
 


Code review comments:
diff_hunk: @@ -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.execute("view.flows.resolve '%s'" % (s))
path: mitmproxy/types.py
text: @user1:
This looks better than before, but we'll now likely run into issues with `'` characters in the spec. Maybe we can just use `manager.call_strings` instead?