From 31db30ec2293defb6631cb6d51251e21fa4ebae5 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Sun, 28 Apr 2019 21:19:46 -0500 Subject: [PATCH] - Only decode input in ``html_quote`` when needed under Python 3 --- CHANGES.rst | 3 +++ src/DocumentTemplate/html_quote.py | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index a88a20f..7519220 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ Changelog 3.0b9 (unreleased) ------------------ +- Only decode input in ``html_quote`` when needed under Python 3 + (`Products.PythonScripts#28 ) + 3.0b8 (2019-04-26) ------------------ diff --git a/src/DocumentTemplate/html_quote.py b/src/DocumentTemplate/html_quote.py index 47590c6..69a1f7f 100644 --- a/src/DocumentTemplate/html_quote.py +++ b/src/DocumentTemplate/html_quote.py @@ -10,9 +10,8 @@ def html_quote(v, name='(Unknown name)', md={}, encoding=None): - if encoding is None: - encoding = 'Latin-1' # the old default v = ustr(v) - if isinstance(v, six.binary_type): - v = v.decode(encoding) + if six.PY3 and isinstance(v, six.binary_type): + # decode using the old default if no encoding is passed + v = v.decode(encoding or 'Latin-1') return escape(v, 1)