From d95f28e6bf581c65a06d410137160a50e584dbfd Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 13 Jun 2017 09:33:29 +1200 Subject: [PATCH] config: don't crash with a config file containing only comments --- mitmproxy/optmanager.py | 2 ++ test/mitmproxy/test_optmanager.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py index 70f60bb64..1680d3468 100644 --- a/mitmproxy/optmanager.py +++ b/mitmproxy/optmanager.py @@ -432,6 +432,8 @@ def parse(text): raise exceptions.OptionsError("Could not parse options.") if isinstance(data, str): raise exceptions.OptionsError("Config error - no keys found.") + elif data is None: + return {} return data diff --git a/test/mitmproxy/test_optmanager.py b/test/mitmproxy/test_optmanager.py index 04ec7ded8..cadc5d768 100644 --- a/test/mitmproxy/test_optmanager.py +++ b/test/mitmproxy/test_optmanager.py @@ -257,6 +257,10 @@ def test_serialize(): with pytest.raises(Exception, match="Config error"): optmanager.load(o2, t) + t = "# a comment" + optmanager.load(o2, t) + assert optmanager.load(o2, "foobar: '123'") == {"foobar": "123"} + t = "" optmanager.load(o2, t) assert optmanager.load(o2, "foobar: '123'") == {"foobar": "123"}