aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/contentviews.py5
-rw-r--r--test/mitmproxy/test_contentview.py8
2 files changed, 8 insertions, 5 deletions
diff --git a/mitmproxy/contentviews.py b/mitmproxy/contentviews.py
index 304b5241..dacef36d 100644
--- a/mitmproxy/contentviews.py
+++ b/mitmproxy/contentviews.py
@@ -262,7 +262,7 @@ class ViewHTMLOutline(View):
content_types = ["text/html"]
def __call__(self, data, **metadata):
- data = data.decode("utf-8")
+ data = data.decode("utf-8", "replace")
h = html2text.HTML2Text(baseurl="")
h.ignore_images = True
h.body_width = 0
@@ -389,7 +389,8 @@ class ViewJavaScript(View):
def __call__(self, data, **metadata):
opts = jsbeautifier.default_options()
opts.indent_size = 2
- res = jsbeautifier.beautify(strutils.native(data), opts)
+ data = data.decode("utf-8", "replace")
+ res = jsbeautifier.beautify(data, opts)
return "JavaScript", format_text(res)
diff --git a/test/mitmproxy/test_contentview.py b/test/mitmproxy/test_contentview.py
index aad53b37..66cad47b 100644
--- a/test/mitmproxy/test_contentview.py
+++ b/test/mitmproxy/test_contentview.py
@@ -78,6 +78,7 @@ class TestContentView:
v = cv.ViewHTMLOutline()
s = b"<html><br><br></br><p>one</p></html>"
assert v(s)
+ assert v(b'\xfe')
def test_view_json(self):
cv.VIEW_CUTOFF = 100
@@ -106,9 +107,10 @@ class TestContentView:
def test_view_javascript(self):
v = cv.ViewJavaScript()
- assert v("[1, 2, 3]")
- assert v("[1, 2, 3")
- assert v("function(a){[1, 2, 3]}")
+ assert v(b"[1, 2, 3]")
+ assert v(b"[1, 2, 3")
+ assert v(b"function(a){[1, 2, 3]}")
+ assert v(b"\xfe") # invalid utf-8
def test_view_css(self):
v = cv.ViewCSS()