From 059710b2b07e30effa5443fb56e05eae66d97d13 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 25 Sep 2017 17:00:43 +0200 Subject: [PATCH] [FIX] reading of HTML and XML view fields in P3 Reading them as bytes would not crash but could fill the corresponding field with pretty much garbage. Turns out Html fields inherit from Text and XML content generally goes into text fields, so handling these items as text makes much more sense than as binary data. --- odoo/tools/convert.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/odoo/tools/convert.py b/odoo/tools/convert.py index 60f9bfa83ad..59e87d6ee32 100644 --- a/odoo/tools/convert.py +++ b/odoo/tools/convert.py @@ -116,29 +116,29 @@ def _eval_xml(self, node, env): 'Could not eval(%s) for %s in %s', a_eval, node.get('name'), env.context) raise def _process(s): - matches = re.finditer(br'[^%]%\((.*?)\)[ds]', s) + matches = re.finditer(br'[^%]%\((.*?)\)[ds]'.decode('utf-8'), s) done = set() for m in matches: found = m.group()[1:] if found in done: continue done.add(found) - id = m.groups()[0].decode('utf-8') + id = m.groups()[0] if not id in self.idref: self.idref[id] = self.id_get(id) # So funny story: in Python 3, bytes(n: int) returns a # bytestring of n nuls. In Python 2 it obviously returns the # stringified number, which is what we're expecting here - s = s.replace(found, pycompat.text_type(self.idref[id]).encode('utf-8')) - s = s.replace(b'%%', b'%') # Quite wierd but it's for (somewhat) backward compatibility sake + s = s.replace(found, pycompat.text_type(self.idref[id])) + s = s.replace('%%', '%') # Quite wierd but it's for (somewhat) backward compatibility sake return s if t == 'xml': _fix_multiple_roots(node) - return b'\n'\ - +_process(b"".join(etree.tostring(n, encoding='utf-8') for n in node)) + return '\n'\ + +_process("".join(etree.tostring(n, encoding='unicode') for n in node)) if t == 'html': - return _process(b"".join(etree.tostring(n, encoding='utf-8') for n in node)) + return _process("".join(etree.tostring(n, encoding='unicode') for n in node)) data = node.text if node.get('file'):