Fix handling of comments with invalid transforms. Write an error msg to the log and just return the untransformed text.
This commit is contained in:
parent
08f11534ea
commit
c47689af42
@ -21,6 +21,10 @@ Changelog
|
||||
default type is set properly when creating a new comment.
|
||||
[timo]
|
||||
|
||||
- Fix handling of comments with invalid transforms. Write an error msg
|
||||
to the log and just return the untransformed text.
|
||||
[timo]
|
||||
|
||||
|
||||
2.1.8 (unreleased)
|
||||
------------------
|
||||
|
@ -142,10 +142,22 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
|
||||
return ''
|
||||
if isinstance(text, unicode):
|
||||
text = text.encode('utf8')
|
||||
return transforms.convertTo(targetMimetype,
|
||||
text,
|
||||
context=self,
|
||||
mimetype=sourceMimetype).getData()
|
||||
transform = transforms.convertTo(
|
||||
targetMimetype,
|
||||
text,
|
||||
context=self,
|
||||
mimetype=sourceMimetype)
|
||||
if transform:
|
||||
return transform.getData()
|
||||
else:
|
||||
logger = logging.getLogger("plone.app.discussion")
|
||||
logger.error(
|
||||
_(u"Transform '%s' => '%s' not available. Failed to transform comment '%s'." % (
|
||||
sourceMimetype,
|
||||
targetMimetype,
|
||||
self.absolute_url(),
|
||||
)))
|
||||
return text
|
||||
|
||||
def Title(self):
|
||||
"""The title of the comment.
|
||||
|
@ -177,6 +177,16 @@ class CommentTest(unittest.TestCase):
|
||||
comment1.text = 'para'
|
||||
self.assertEqual(comment1.getText(targetMimetype='text/plain'), 'para')
|
||||
|
||||
def test_getText_invalid_transformation_raises_error(self):
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.mime_type = 'text/x-html-safe'
|
||||
comment1.text = 'para'
|
||||
conversation.addComment(comment1)
|
||||
self.assertEqual(
|
||||
comment1.getText(targetMimetype='text/html'),
|
||||
'para')
|
||||
|
||||
def test_traversal(self):
|
||||
# make sure comments are traversable, have an id, absolute_url and
|
||||
# physical path
|
||||
|
Loading…
Reference in New Issue
Block a user