summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@jelmer.uk>2019-03-07 02:51:12 -0800
committerChris Dent <chris.dent@gmail.com>2019-03-07 10:51:12 +0000
commit1cccef8ca1257b36d33ac48563b3ea996575c550 (patch)
tree25a4585152efe744be6e65fefb436fcaf0b21a5b
parent4bd9871effb3192fa1973ef2cafa1923eaa0ff01 (diff)
downloadpaste-git-1cccef8ca1257b36d33ac48563b3ea996575c550.tar.gz
Fix quoting of bytestrings. (#23)
-rw-r--r--paste/util/quoting.py5
-rw-r--r--tests/test_util/test_quoting.py2
2 files changed, 6 insertions, 1 deletions
diff --git a/paste/util/quoting.py b/paste/util/quoting.py
index 58ea308..b3d28a4 100644
--- a/paste/util/quoting.py
+++ b/paste/util/quoting.py
@@ -23,7 +23,10 @@ def html_quote(v, encoding=None):
if v is None:
return ''
elif isinstance(v, six.binary_type):
- return html.escape(v, 1)
+ if six.PY3:
+ return html.escape(v.decode(encoding), 1).encode(encoding)
+ else:
+ return html.escape(v, 1)
elif isinstance(v, six.text_type):
if six.PY3:
return html.escape(v, 1)
diff --git a/tests/test_util/test_quoting.py b/tests/test_util/test_quoting.py
index 5f5e0a8..6df1139 100644
--- a/tests/test_util/test_quoting.py
+++ b/tests/test_util/test_quoting.py
@@ -20,6 +20,8 @@ class TestQuoting(unittest.TestCase):
'')
self.assertEqual(quoting.html_quote('<hey!>'),
'&lt;hey!&gt;')
+ self.assertEqual(quoting.html_quote(b'<hey!>'),
+ b'&lt;hey!&gt;')
if six.PY3:
self.assertEqual(quoting.html_quote(u'<\u1029>'),
u'&lt;\u1029&gt;')