From 3d4d87b718b019af6340827a00aa4e08e3ec924f Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 17 Jan 2011 19:44:44 +0100 Subject: [PATCH] [FIX] report.interface: toxml() should return unicode to avoid any encoding issue propagation It used to return utf-8 data but was brittle in the conversion, and would fail downstream if the calling code did not pay attention to handle utf-8 data properly. Returning unicode forces callers to auto-cast to unicode for any string operation, saving potential trouble later. From the addons that currently call toxml(), none use it in a manner that would fail in case unicode data is returned, so we should be on the safe side there too. lp bug: https://launchpad.net/bugs/695960 fixed bzr revid: odo@openerp.com-20110117184444-mxjeneuoa0r5a85n --- bin/report/interface.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/report/interface.py b/bin/report/interface.py index ce14883986c..36f54b31fdb 100644 --- a/bin/report/interface.py +++ b/bin/report/interface.py @@ -33,16 +33,12 @@ import render import urllib # -# encode a value to a string in utf8 and converts XML entities +# coerce any type to a unicode string (to preserve non-ascii characters) +# and escape XML entities # -def toxml(val): - if isinstance(val, str): - str_utf8 = val - elif isinstance(val, unicode): - str_utf8 = val.encode('utf-8') - else: - str_utf8 = str(val) - return str_utf8.replace('&', '&').replace('<','<').replace('>','>') +def toxml(value): + unicode_value = tools.ustr(value) + return unicode_value.replace('&', '&').replace('<','<').replace('>','>') class report_int(netsvc.Service): def __init__(self, name, audience='*'):