diff --git a/backlash/utils.py b/backlash/utils.py index 1693c85..e3297a2 100644 --- a/backlash/utils.py +++ b/backlash/utils.py @@ -21,10 +21,7 @@ def escape(s, quote=False): if not isinstance(s, (str, bytes)): s = str(s) if isinstance(s, bytes): - try: - s.decode('ascii') - except Exception: - s = s.decode('utf-8', 'replace') + s = s.decode('utf-8', 'replace') s = s.replace('&', '&').replace('<', '<').replace('>', '>') if quote: s = s.replace('"', """) diff --git a/tests/test_utils.py b/tests/test_utils.py index c1bef55..9a89cf4 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -10,4 +10,5 @@ def test_escape_normalizes_values(): assert escape(None) == '' assert escape(42) == '42' assert escape(b'pi\xc3\xb9 ') == 'pi\u00f9 <b>' + assert escape(b'hello') == 'hello' assert escape('say "hi"', quote=True) == 'say "hi"'