[FIX] ir.qweb: rendering non-string attributes could cause unicode errors (Issue...
authorOlivier Dony <odo@openerp.com>
Tue, 3 Jun 2014 22:08:01 +0000 (00:08 +0200)
committerOlivier Dony <odo@openerp.com>
Thu, 5 Jun 2014 08:11:23 +0000 (10:11 +0200)
This occurs because werkzeug.utils.escape() auto-casts
non-basestring values to unicode, while we expect to be
working with bytestrings only.
So when evaluating attribute values, make sure we always
return bytestring values, never int, bool or unicode.

openerp/addons/base/ir/ir_qweb.py

index 11c2432..6e434c2 100644 (file)
@@ -334,10 +334,10 @@ class QWeb(orm.AbstractModel):
             att, val = attribute_name[7:], self.eval_format(attribute_value, qwebcontext)
         elif attribute_name.startswith("t-att-"):
             att, val = attribute_name[6:], self.eval(attribute_value, qwebcontext)
-            if isinstance(val, unicode):
-                val = val.encode("utf8")
         else:
             att, val = self.eval_object(attribute_value, qwebcontext)
+        if val and not isinstance(val, str):
+            val = unicode(val).encode("utf8")
         return att, val
 
     # Tags