Skip to content

Commit

Permalink
Merge pull request #34 from plone/issue_33
Browse files Browse the repository at this point in the history
fix UnicodeDecodeError when linked image has non-ascii characters in title or description
  • Loading branch information
pbauer authored Mar 15, 2019
2 parents 8673e29 + e5be14b commit d7b87ad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 4 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -23,7 +25,7 @@ Bug fixes:
Bug fixes:

- bugfix for KeyError caused by <a> elements without href attribute
[ajung]
[ajung]


3.1.0 (2018-11-02)
Expand Down
4 changes: 2 additions & 2 deletions plone/outputfilters/filters/resolveuid_and_caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions plone/outputfilters/tests/test_resolveuid_and_caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 = """<img class="captioned" src="resolveuid/foo2/@@images/image/thumb"/>"""
text_out = """<img alt="foo2" class="captioned" src="http://nohost/plone/foo2/@@images/...jpeg" title="foo2"/>"""
text_out = u"""<img alt="Schönes Bild" class="captioned" src="http://nohost/plone/foo2/@@images/...jpeg" title="Schönes Bild"/>"""
self._assertTransformsTo(text_in, text_out)

def test_image_captioning_resolveuid_no_scale(self):
Expand All @@ -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 = """<img class="captioned" src="resolveuid/foo2/@@images/image"/>"""
text_out = """<img alt="foo2" class="captioned" src="http://nohost/plone/foo2/@@images/...jpeg" title="foo2"/>"""
text_out = u"""<img alt="Schönes Bild" class="captioned" src="http://nohost/plone/foo2/@@images/...jpeg" title="Schönes Bild"/>"""
self._assertTransformsTo(text_in, text_out)

def test_image_captioning_bad_uid(self):
Expand Down

0 comments on commit d7b87ad

Please sign in to comment.