Commit 0162ede8 authored by Jérome Perrin's avatar Jérome Perrin

core: Fix unicode bug on ZODB History view.

Some objects, in our case BTrees.Length.Length in a ZODB connection
have a __str__ method that returns unicode on python2:

u'<BTrees.Length.Length object at 0x7f850932e0d0 oid 0x1e334 in <Connection at 7f854bc0f190>>'

They cause an unicode error in the history view when they are
concatenated together with other str (encoded as UTF-8) properties,
this can be observed when using history view with a "folderish"
document (but not with a File as in test_ZODBHistoryBinaryData).

To prevent this issue, we use the fact that ''.format unlike '' %
seem to apply a str() on arguments and use it instead.
Co-authored-by: Yusei Tahara's avatarYusei Tahara <yusei@nexedi.com>
parent 7d32a4f9
Pipeline #24317 failed with stage
in 0 seconds
...@@ -134,6 +134,17 @@ class TestZODBHistory(ERP5TypeTestCase): ...@@ -134,6 +134,17 @@ class TestZODBHistory(ERP5TypeTestCase):
from zExceptions import Unauthorized from zExceptions import Unauthorized
self.assertRaises(Unauthorized, document.Base_viewZODBHistory) self.assertRaises(Unauthorized, document.Base_viewZODBHistory)
def test_ZODBHistoryNonAsciiProperty(self):
self.loginByUserName('tatuya')
document = self.addOrganisation(self.id())
document.edit(title='ネクセディ', default_address_city='千代田区')
self.commit()
_, change, = document.Base_getZODBHistoryList()
self.assertIn('title:ネクセディ', change.getProperty('changes'))
# no encoding error
document.Base_viewZODBHistory()
def test_ZODBHistoryBinaryData(self): def test_ZODBHistoryBinaryData(self):
""" """
Make sure ZODB History view works with binary content Make sure ZODB History view works with binary content
......
...@@ -16,7 +16,7 @@ def beautifyChange(change_dict): ...@@ -16,7 +16,7 @@ def beautifyChange(change_dict):
six.text_type(property_value, 'utf-8') six.text_type(property_value, 'utf-8')
except UnicodeDecodeError: except UnicodeDecodeError:
property_value = '(binary)' property_value = '(binary)'
change_list.append('%s:%r' % (property_name, property_value)) change_list.append('{}:{}'.format(property_name, property_value))
return change_list return change_list
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment