Use replace while decoding
This commit is contained in:
parent
56d04b5740
commit
1cffa5f46b
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue