Commit 627af881 authored by Jérome Perrin's avatar Jérome Perrin

syncml: use cutXML with str, not bytes

When cutting with bytes, we might cut in the middle of a multi-bytes
character and later decoding it would cause an error. We could switch
to sending bytes encoded to base64, because the limit would be more
natural to be number of bytes, but just decoding and cutting the string
is easier and in practice not so different.

This bug was revealed by testERP5SyncML.TestERP5SyncML.test_28_PartialData
with PYTHONHASHSEED 872 and test_28_PartialData with PYTHONHASHSEED 238
( on python2 )
parent dde9d338
...@@ -220,12 +220,12 @@ class SyncMLSignature(XMLObject): ...@@ -220,12 +220,12 @@ class SyncMLSignature(XMLObject):
def getFirstPdataChunk(self, max_len): def getFirstPdataChunk(self, max_len):
""" """
""" """
partial_data = self._baseGetPartialData() partial_data = bytes(self._baseGetPartialData()).decode('utf-8')
chunk = partial_data[:max_len] chunk = partial_data[:max_len]
rest_in_queue = partial_data[max_len:] rest_in_queue = partial_data[max_len:]
if rest_in_queue is not None: if rest_in_queue is not None:
self.setPartialData(rest_in_queue) self.setPartialData(rest_in_queue.encode('utf-8'))
return bytes(chunk) return chunk.encode('utf-8')
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'setSubscriberXupdate') 'setSubscriberXupdate')
......
...@@ -192,13 +192,15 @@ def getXupdateObject(object_xml=None, old_xml=None): ...@@ -192,13 +192,15 @@ def getXupdateObject(object_xml=None, old_xml=None):
def cutXML(xml_string, length=None): def cutXML(xml_string, length=None):
""" """
Sliced a xml tree a return two fragment Sliced a xml tree and return two fragments
""" """
if length is None: if length is None:
length = MAX_LEN length = MAX_LEN
if not isinstance(xml_string, six.text_type):
xml_string = xml_string.decode('utf-8')
short_string = xml_string[:length] short_string = xml_string[:length]
rest_string = xml_string[length:] rest_string = xml_string[length:]
xml_string = etree.CDATA(short_string.decode('utf-8')) xml_string = etree.CDATA(short_string)
return xml_string, rest_string return xml_string, rest_string
class XMLSyncUtilsMixin(object): class XMLSyncUtilsMixin(object):
......
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