Skip to content

Commit

Permalink
Merge pull request #15 from plone/datakurre-fix-decode
Browse files Browse the repository at this point in the history
Fix marshaler decode to decode raw value as unicode (IText)
  • Loading branch information
tisto committed Jan 23, 2015
2 parents 23bc04d + d44e186 commit 2235261
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
14 changes: 14 additions & 0 deletions docs/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ Changelog
1.2.5 (unreleased)
------------------

- Fix marshaler decode to always decode raw value into unicode
[datakurre]

- Remove utils.getSiteEncoding, which was deprecated and not used anywhere.
[thet]

- For Plone 5, support getting markup control panel settings from the registry,
while still supporting normal portal_properties access for Plone < 5.
[thet]

- Resolved an interesting circular import case, which wasnt effective because
of sort order of imports
[thet]

- For Plone 5, support getting markup control panel settings from the registry,
while still supporting normal portal_properties access for Plone < 5.
[thet]
Expand Down
6 changes: 5 additions & 1 deletion plone/app/textfield/marshaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ def decode(
charset='utf-8',
contentType=None,
primary=False):
try:
unicode_value = value.decode(charset)
except UnicodeEncodeError:
unicode_value = value # was already unicode
return RichTextValue(
raw=value,
raw=unicode_value,
mimeType=contentType or self.field.default_mime_type,
outputMimeType=self.field.output_mime_type,
encoding=charset
Expand Down
6 changes: 3 additions & 3 deletions plone/app/textfield/marshaler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ We can now look up and test the marshaler:
'Some \xc3\x98 plain text'
>>> decoded = marshaler.decode('Some \xc3\x98 plain text', charset='utf-8', contentType='text/plain')
>>> decoded.raw
'Some \xc3\x98 plain text'
u'Some \xd8 plain text'
>>> decoded.mimeType
'text/plain'
>>> decoded.outputMimeType
Expand All @@ -72,7 +72,7 @@ default type is used.

>>> decoded = marshaler.decode('Some \xc3\x98 plain text')
>>> decoded.raw
'Some \xc3\x98 plain text'
u'Some \xd8 plain text'
>>> decoded.mimeType
'text/plain'
>>> decoded.outputMimeType
Expand Down Expand Up @@ -108,7 +108,7 @@ Let's now use this message to construct a new object.
>>> from plone.rfc822 import initializeObjectFromSchema
>>> initializeObjectFromSchema(newContent, ITestContent, inputMessage)
>>> newContent._text.raw
'Some \xc3\x98 plain text'
u'Some \xd8 plain text'
>>> newContent._text.mimeType
'text/plain'
>>> newContent._text.outputMimeType
Expand Down

1 comment on commit 2235261

@mister-roboto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TESTS FAILED
Mr.roboto url : http://jenkins.plone.org/roboto/get_info?push=caf3f6eb99634d91837b9f5d7b6e33b1
plone-4.3-python-2.6 [FAILURE]
plone-4.3-python-2.7 [SUCCESS]
plone-5.0-python-2.7 [SUCCESS]

Please sign in to comment.