Commit e503e504 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 on python2
parent e1f7c242
...@@ -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