Skip to content

Commit

Permalink
let "unicode conflict resolution" work for all templates
Browse files Browse the repository at this point in the history
  • Loading branch information
d-maurer committed Jul 9, 2020
1 parent 37545ab commit 98a8be1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ https://zope.readthedocs.io/en/2.13/CHANGES.html
4.5.1 (unreleased)
------------------

- Let "unicode conflict resolution" work for all templates (not just
``ZopePageTemplate``).

- Update dependencies to the latest releases that still support Python 2.


Expand Down
3 changes: 2 additions & 1 deletion src/Products/PageTemplates/Expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ def _handleText(self, text, expr):
return text.decode('ascii')

try:
return resolver.resolve(self.contexts['context'], text, expr)
return resolver.resolve(
self.contexts.get('context'), text, expr)
except UnicodeDecodeError as e:
LOG.error("UnicodeDecodeError detected for expression \"%s\"\n"
"Resolver class: %s\n"
Expand Down
8 changes: 8 additions & 0 deletions src/Products/PageTemplates/tests/testHTMLTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from Products.PageTemplates.tests import util
from Products.PageTemplates.unicodeconflictresolver import \
DefaultUnicodeEncodingConflictResolver
from Products.PageTemplates.unicodeconflictresolver import \
PreferredCharsetResolver
from zope.component import provideUtility
from zope.traversing.adapters import DefaultTraversable

Expand Down Expand Up @@ -200,3 +202,9 @@ def testDefaultKeywordHandling(self):

def testSwitch(self):
self.assert_expected(self.folder.t, 'switch.html')

def test_unicode_conflict_resolution(self):
# override with the more "demanding" resolver
provideUtility(PreferredCharsetResolver)
t = PageTemplate()
self.assert_expected(t, 'UnicodeResolution.html')
3 changes: 3 additions & 0 deletions src/Products/PageTemplates/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def getPhysicalRoot(self):


def check_html(s1, s2):
if not isinstance(s2, bytes) and isinstance(s1, bytes):
# convert to common type
s1 = s1.decode("utf-8") # our encoding
s1 = normalize_html(s1)
s2 = normalize_html(s2)
TEST_CASE.assertEqual(s1, s2)
Expand Down

0 comments on commit 98a8be1

Please sign in to comment.