diff --git a/mitmproxy/contentviews/graphql.py b/mitmproxy/contentviews/graphql.py index 5263b75f5..b76b7bf05 100644 --- a/mitmproxy/contentviews/graphql.py +++ b/mitmproxy/contentviews/graphql.py @@ -30,7 +30,12 @@ def is_graphql_query(data): def is_graphql_batch_query(data): - return isinstance(data, list) and isinstance(data[0], dict) and "query" in data[0] + return ( + isinstance(data, list) + and len(data) > 0 + and isinstance(data[0], dict) + and "query" in data[0] + ) class ViewGraphQL(base.View): diff --git a/test/mitmproxy/contentviews/test_graphql.py b/test/mitmproxy/contentviews/test_graphql.py index 89beda814..f10af244f 100644 --- a/test/mitmproxy/contentviews/test_graphql.py +++ b/test/mitmproxy/contentviews/test_graphql.py @@ -19,6 +19,7 @@ def test_render_priority(): assert 0 == v.render_priority( b"""[{"xquery": "query P { \\n }"}]""", content_type="application/json" ) + assert 0 == v.render_priority(b"""[]""", content_type="application/json") assert 0 == v.render_priority(b"}", content_type="application/json") diff --git a/test/mitmproxy/contentviews/test_json.py b/test/mitmproxy/contentviews/test_json.py index 9711a6465..413f19fd5 100644 --- a/test/mitmproxy/contentviews/test_json.py +++ b/test/mitmproxy/contentviews/test_json.py @@ -78,6 +78,22 @@ def test_format_json(): [("text", " "), ("text", "]"), ("text", "")], [("text", ""), ("text", "}")], ] + assert list(json.format_json({"list": []})) == [ + [("text", "{"), ("text", "")], + [ + ("text", " "), + ("Token_Name_Tag", '"list"'), + ("text", ": "), + ("text", "[]"), + ("text", ""), + ], + [("text", ""), ("text", "}")], + ] + assert list(json.format_json(None)) == [[("Token_Keyword_Constant", "null")]] + assert list(json.format_json(True)) == [[("Token_Keyword_Constant", "true")]] + assert list(json.format_json(1)) == [[("Token_Literal_Number", "1")]] + assert list(json.format_json("test")) == [[("Token_Literal_String", '"test"')]] + assert list(json.format_json([])) == [[("text", "[]")]] def test_view_json(): @@ -88,6 +104,7 @@ def test_view_json(): assert v(b"[1, 2, 3, 4, 5]") assert v(b'{"foo" : 3}') assert v(b'{"foo": true, "nullvalue": null}') + assert v(b"[]") @given(binary())