summaryrefslogtreecommitdiff
path: root/bin/report/interface.py
diff options
context:
space:
mode:
authorOlivier Dony <odo@openerp.com>2011-01-17 19:44:44 +0100
committerOlivier Dony <odo@openerp.com>2011-01-17 19:44:44 +0100
commit3d4d87b718b019af6340827a00aa4e08e3ec924f (patch)
treedf52e887e145237bb509cb8404250c3c966e0602 /bin/report/interface.py
parent6cd9f649737777e47f193c04491fc382f7885ba9 (diff)
[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
Diffstat (limited to 'bin/report/interface.py')
-rw-r--r--bin/report/interface.py14
1 files 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('&', '&amp;').replace('<','&lt;').replace('>','&gt;')
+def toxml(value):
+ unicode_value = tools.ustr(value)
+ return unicode_value.replace('&', '&amp;').replace('<','&lt;').replace('>','&gt;')
class report_int(netsvc.Service):
def __init__(self, name, audience='*'):