Unicode error in Page Templates

Bug #143868 reported by Yury Don
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zope 2
Invalid
Medium
Andreas Jung

Bug Description

I add Page Template, set Content-Type to text/plain, output-encofing to koi8-r, write text with cyrillic characters and try to save it. And get an error:
Error Type: TypeError
Error Value: decoding Unicode is not supported
Environment:
management_page_charset property set to "koi8-r"
environment variable ZPT_PREFERRED_ENCODING="koi8-r"
overrides.zcml in /Products/PageTemplates with ReplacingUnicodeEncodingConflictResolver
Error was gone after adding 2 lines in /Products/PageTemplates/utils.py in function convertToUnicode:
replace
        try:
            return unicode(source, enc), enc
        except UnicodeDecodeError:
                continue

with

        try:
            return unicode(source, enc), enc
        except UnicodeDecodeError:
                continue
        except TypeError:
                continue

Revision history for this message
Andreas Jung (ajung) wrote :

Could you please work on a unittest?

Revision history for this message
Erich Seifert (e-seifert) wrote :

I ran into a similar problem after updating from 2.10.1 to 2.10.2. When I tried to save the contents of an existing ZPT object containing an Atom feed (content type is "application/atom+xml") I also got the TypeError "decoding Unicode is not supported" from convertToUnicode(). After changing content type to "text/xml" I was able to change the contents without problems.

My first try to solve the problem was to replace line 66 of PageTemplates/utils.py from

> if content_type.startswith('text/xml'):

to

> if content_type.startswith('text/xml') or content_type.endswith('+xml'):

but that didn't help. So as quick fix I added an additional check to the top of convertToUnicode in PageTemplates/utils.py:

> if isinstance(source, unicode):
> return source, None

which solved the problem for now.

Revision history for this message
Andreas Jung (ajung) wrote :

*Please* submit a unittest that demonstrates the error. Further "me too" messages are not so helpful.

Andreas Jung (ajung)
Changed in zope2:
assignee: nobody → ajung
Changed in zope2:
status: New → Confirmed
Revision history for this message
Colin Watson (cjwatson) wrote :

The zope2 project on Launchpad has been archived at the request of the Zope developers (see https://answers.launchpad.net/launchpad/+question/683589 and https://answers.launchpad.net/launchpad/+question/685285). If this bug is still relevant, please refile it at https://github.com/zopefoundation/zope2.

Changed in zope2:
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.