diff --git a/mitmproxy/contentviews/image/image_parser.py b/mitmproxy/contentviews/image/image_parser.py index 46549b1b9..aa6f84509 100644 --- a/mitmproxy/contentviews/image/image_parser.py +++ b/mitmproxy/contentviews/image/image_parser.py @@ -91,11 +91,12 @@ def parse_ico(data: bytes) -> Metadata: for i, image in enumerate(img.images): parts.append( ( - 'Image {}'.format(i), "Size: {} x {}\n " - "Bits per pixel: {}\n " - "PNG: {}".format(256 if not image.width else image.width, - 256 if not image.height else image.height, - image.bpp, image.is_png) + 'Image {}'.format(i+1), "Size: {} x {}\n" + "{: >18}Bits per pixel: {}\n" + "{: >18}PNG: {}".format(256 if not image.width else image.width, + 256 if not image.height else image.height, + '', image.bpp, + '', image.is_png) ) ) diff --git a/test/mitmproxy/contentviews/image/test_image_parser.py b/test/mitmproxy/contentviews/image/test_image_parser.py index 3cb44ca6a..fdc72165b 100644 --- a/test/mitmproxy/contentviews/image/test_image_parser.py +++ b/test/mitmproxy/contentviews/image/test_image_parser.py @@ -167,3 +167,26 @@ def test_parse_gif(filename, metadata): def test_parse_jpeg(filename, metadata): with open(tutils.test_data.path(filename), 'rb') as f: assert metadata == image_parser.parse_jpeg(f.read()) + + +@pytest.mark.parametrize("filename, metadata", { + "mitmproxy/data/image.ico": [ + ('Format', 'ICO'), + ('Number of images', '3'), + ('Image 1', "Size: {} x {}\n" + "{: >18}Bits per pixel: {}\n" + "{: >18}PNG: {}".format(48, 48, '', 24, '', False) + ), + ('Image 2', "Size: {} x {}\n" + "{: >18}Bits per pixel: {}\n" + "{: >18}PNG: {}".format(32, 32, '', 24, '', False) + ), + ('Image 3', "Size: {} x {}\n" + "{: >18}Bits per pixel: {}\n" + "{: >18}PNG: {}".format(16, 16, '', 24, '', False) + ) + ] +}.items()) +def test_ico(filename, metadata): + with open(tutils.test_data.path(filename), 'rb') as f: + assert metadata == image_parser.parse_ico(f.read()) diff --git a/test/mitmproxy/contentviews/image/test_view.py b/test/mitmproxy/contentviews/image/test_view.py index 34f655a13..6da5b1d0b 100644 --- a/test/mitmproxy/contentviews/image/test_view.py +++ b/test/mitmproxy/contentviews/image/test_view.py @@ -9,8 +9,7 @@ def test_view_image(): "mitmproxy/data/image.png", "mitmproxy/data/image.gif", "mitmproxy/data/all.jpeg", - # https://bugs.python.org/issue21574 - # "mitmproxy/data/image.ico", + "mitmproxy/data/image.ico", ]: with open(tutils.test_data.path(img), "rb") as f: viewname, lines = v(f.read())