From 633bc350d225eb02c7ab0aef6bae57c4def560e1 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Mon, 8 Jan 2018 21:14:35 +0800 Subject: Fix #2760 --- mitmproxy/addons/view.py | 6 +++++- test/mitmproxy/addons/test_view.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py index 5fbefdb0..68a3a72b 100644 --- a/mitmproxy/addons/view.py +++ b/mitmproxy/addons/view.py @@ -441,7 +441,11 @@ class View(collections.Sequence): @command.command("view.create") def create(self, method: str, url: str) -> None: - req = http.HTTPRequest.make(method.upper(), url) + try: + req = http.HTTPRequest.make(method.upper(), url) + except ValueError as e: + ctx.log.error(e) + return c = connections.ClientConnection.make_dummy(("", 0)) s = connections.ServerConnection.make_dummy((req.host, req.port)) f = http.HTTPFlow(c, s) diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index 6e4af367..72f1a0fb 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -147,6 +147,9 @@ def test_create(): assert v[0].request.url == "http://foo.com/" v.create("get", "http://foo.com") assert len(v) == 2 + v.create("get", "http://foo.com\\") + v.create("get", "http://") + assert len(v) == 2 def test_orders(): -- cgit v1.2.3 From a6f6f8cd3226de3c89ec9d6cdeab972c88b94a18 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Mon, 8 Jan 2018 21:51:03 +0800 Subject: Raise a CommandError for the exception --- mitmproxy/addons/view.py | 3 +-- test/mitmproxy/addons/test_view.py | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py index 68a3a72b..c3fb4b88 100644 --- a/mitmproxy/addons/view.py +++ b/mitmproxy/addons/view.py @@ -444,8 +444,7 @@ class View(collections.Sequence): try: req = http.HTTPRequest.make(method.upper(), url) except ValueError as e: - ctx.log.error(e) - return + raise exceptions.CommandError("Invalid URL: %s" % e) c = connections.ClientConnection.make_dummy(("", 0)) s = connections.ServerConnection.make_dummy((req.host, req.port)) f = http.HTTPFlow(c, s) diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index 72f1a0fb..a95d059d 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -147,9 +147,10 @@ def test_create(): assert v[0].request.url == "http://foo.com/" v.create("get", "http://foo.com") assert len(v) == 2 - v.create("get", "http://foo.com\\") - v.create("get", "http://") - assert len(v) == 2 + with pytest.raises(exceptions.CommandError, match="Invalid URL"): + v.create("get", "http://foo.com\\") + with pytest.raises(exceptions.CommandError, match="Invalid URL"): + v.create("get", "http://") def test_orders(): -- cgit v1.2.3