diff --git a/mitmproxy/contentviews/msgpack.py b/mitmproxy/contentviews/msgpack.py index 92aeb8b39..8de6c9abb 100644 --- a/mitmproxy/contentviews/msgpack.py +++ b/mitmproxy/contentviews/msgpack.py @@ -64,11 +64,11 @@ def format_msgpack( elif type(data) is list: output[-1] += [("text", "[")] - for item in data: + + for count, item in enumerate(data): output.append([indent, ("text", " ")]) format_msgpack(item, output, indent_count + 1) - - if item != data[-1]: + if count != len(data) - 1: output[-1] += [("text", ",")] output.append([indent, ("text", "]")]) diff --git a/test/mitmproxy/contentviews/test_msgpack.py b/test/mitmproxy/contentviews/test_msgpack.py index 65c8487f0..d3c53d3a9 100644 --- a/test/mitmproxy/contentviews/test_msgpack.py +++ b/test/mitmproxy/contentviews/test_msgpack.py @@ -57,7 +57,9 @@ def test_format_msgpack(): [("text", ""), ("text", "}")], ] - assert list(msgpack.format_msgpack({"object": {"key": "value"}, "list": [1]})) == [ + assert list( + msgpack.format_msgpack({"object": {"key": "value"}, "list": [0, 0, 1, 0, 0]}) + ) == [ [("text", "{")], [ ("text", ""), @@ -81,7 +83,31 @@ def test_format_msgpack(): ("text", ": "), ("text", "["), ], - [("text", " "), ("text", " "), ("Token_Literal_Number", "1")], + [ + ("text", " "), + ("text", " "), + ("Token_Literal_Number", "0"), + ("text", ","), + ], + [ + ("text", " "), + ("text", " "), + ("Token_Literal_Number", "0"), + ("text", ","), + ], + [ + ("text", " "), + ("text", " "), + ("Token_Literal_Number", "1"), + ("text", ","), + ], + [ + ("text", " "), + ("text", " "), + ("Token_Literal_Number", "0"), + ("text", ","), + ], + [("text", " "), ("text", " "), ("Token_Literal_Number", "0")], [("text", " "), ("text", "]")], [("text", ""), ("text", "}")], ]