From e5be14b37fe77a9358de481e5b2b52378fcd285a Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Thu, 14 Mar 2019 16:40:01 +0100 Subject: [PATCH] fix UnicodeDecodeError when linked image has non-ascii characters in title or description this is only in python2 --- CHANGES.rst | 6 ++++-- plone/outputfilters/filters/resolveuid_and_caption.py | 4 ++-- plone/outputfilters/tests/test_resolveuid_and_caption.py | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index d8c1771..bd9a979 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,7 +14,9 @@ New features: Bug fixes: -- *add item here* +- fix UnicodeDecodeError in Python 2 when uid-linked image has + non-ascii characters in title or description + [petschki] 3.1.1 (2019-01-07) @@ -23,7 +25,7 @@ Bug fixes: Bug fixes: - bugfix for KeyError caused by elements without href attribute - [ajung] + [ajung] 3.1.0 (2018-11-02) diff --git a/plone/outputfilters/filters/resolveuid_and_caption.py b/plone/outputfilters/filters/resolveuid_and_caption.py index 13d5655..8904a92 100644 --- a/plone/outputfilters/filters/resolveuid_and_caption.py +++ b/plone/outputfilters/filters/resolveuid_and_caption.py @@ -152,7 +152,7 @@ def __call__(self, data): if fullimage is not None: # Check to see if the alt / title tags need setting - title = aq_acquire(fullimage, 'Title')() + title = safe_unicode(aq_acquire(fullimage, 'Title')()) if not attributes.get('alt'): # XXX alt attribute contains *alternate* text attributes['alt'] = description or title @@ -282,7 +282,7 @@ def traverse_path(base, path): except AttributeError: return None, None, src, description src = url + appendix - description = aq_acquire(fullimage, 'Description')() + description = safe_unicode(aq_acquire(fullimage, 'Description')()) return image, fullimage, src, description def handle_captioned_image(self, attributes, image, fullimage, diff --git a/plone/outputfilters/tests/test_resolveuid_and_caption.py b/plone/outputfilters/tests/test_resolveuid_and_caption.py index ecf4f2a..bf55244 100644 --- a/plone/outputfilters/tests/test_resolveuid_and_caption.py +++ b/plone/outputfilters/tests/test_resolveuid_and_caption.py @@ -54,7 +54,8 @@ def UID(self): allowedRolesAndUsers = ('Anonymous',) class DummyContent2(NFDummyContent): - id = __name__ = title = 'foo2' + id = __name__ = 'foo2' + title = u'Schönes Bild' def UID(self): return 'foo2' @@ -349,7 +350,7 @@ def test_image_captioning_resolveuid_new_scale(self): def test_image_captioning_resolveuid_new_scale_plone_namedfile(self): self._makeDummyContent() text_in = """""" - text_out = """foo2""" + text_out = u"""Schönes Bild""" self._assertTransformsTo(text_in, text_out) def test_image_captioning_resolveuid_no_scale(self): @@ -363,7 +364,7 @@ def test_image_captioning_resolveuid_no_scale(self): def test_image_captioning_resolveuid_no_scale_plone_namedfile(self): self._makeDummyContent() text_in = """""" - text_out = """foo2""" + text_out = u"""Schönes Bild""" self._assertTransformsTo(text_in, text_out) def test_image_captioning_bad_uid(self):