mirror of
https://github.com/pallets-eco/flask-debugtoolbar.git
synced 2026-01-06 05:30:12 -06:00
printable filter should replace non-ascii bytes
In Python 2, when repr() returns bytes, replace any non-ascii bytes with the unicode ? character to ensure that the result is printable. Fixes #66
This commit is contained in:
@@ -30,7 +30,10 @@ def replace_insensitive(string, target, replacement):
|
||||
|
||||
def _printable(value):
|
||||
try:
|
||||
return repr(value)
|
||||
value = repr(value)
|
||||
if isinstance(value, bytes):
|
||||
value = value.decode('ascii', 'replace')
|
||||
return value
|
||||
except Exception as e:
|
||||
return '<repr(%s) raised %s: %s>' % (
|
||||
object.__repr__(value), type(e).__name__, e)
|
||||
|
||||
Reference in New Issue
Block a user