From 48da9ae97311c04bb778e5e6fef5f14d272b26e3 Mon Sep 17 00:00:00 2001 From: Gorash Date: Thu, 5 Aug 2021 14:08:19 +0000 Subject: [PATCH] [FIX] base: t-esc does not escape Markdown content and is equal to t-out This is the same behavior as javascript. Which had been changed during the refactoring of qweb. t-esc asked for escaping whatever the content. However, a lot of templates still use t-esc. It is easier to go back to the previous functionality. --- odoo/addons/base/models/qweb.py | 12 ++-------- odoo/addons/base/tests/test_qweb.py | 37 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/odoo/addons/base/models/qweb.py b/odoo/addons/base/models/qweb.py index d7d374439d5..b2891bbe3ad 100644 --- a/odoo/addons/base/models/qweb.py +++ b/odoo/addons/base/models/qweb.py @@ -1105,13 +1105,7 @@ class QWeb(object): else: code.append(self._indent("force_display = None", indent)) - if ttype == 't-esc': - # deprecated use. - code.append(self._indent(dedent(""" - if content is not None and content is not False: - content = str(content) - """), indent)) - elif ttype == 't-raw': + if ttype == 't-raw': # deprecated use. code.append(self._indent(dedent(""" if content is not None and content is not False: @@ -1125,9 +1119,7 @@ class QWeb(object): # deprecated use. if options.get('dev_mode'): _logger.warning( - "Found deprecated directive @t-esc=%r in template %r. Replace by " - "@t-out, and explicitely wrap content in `str` if " - "necessary (which likely is not the case)", + "Found deprecated directive @t-esc=%r in template %r. Replace by @t-out", el.get('t-esc'), options.get('ref', ''), ) diff --git a/odoo/addons/base/tests/test_qweb.py b/odoo/addons/base/tests/test_qweb.py index ce6009401d3..e754dacf403 100644 --- a/odoo/addons/base/tests/test_qweb.py +++ b/odoo/addons/base/tests/test_qweb.py @@ -989,6 +989,43 @@ class TestQWebBasic(TransactionCase): self.assertEqual(html, """a
b <b>c</b>
""") + def test_out_markup(self): + t = self.env['ir.ui.view'].create({ + 'name': 'test', + 'type': 'qweb', + 'arch_db': ''' + toto +
+ ''' + }) + result = """ +
toto
+ """ + rendered = self.env['ir.qweb']._render(t.id, {}) + self.assertEqual(rendered.strip(), result.strip()) + + def test_esc_markup(self): + # t-esc is equal to t-out + t = self.env['ir.ui.view'].create({ + 'name': 'test', + 'type': 'qweb', + 'arch_db': ''' + toto +
+ ''' + }) + ref = self.env['ir.ui.view'].create({ + 'name': 'test', + 'type': 'qweb', + 'arch_db': ''' + toto +
+ ''' + }) + rendered = self.env['ir.qweb']._render(t.id, {}) + result = self.env['ir.qweb']._render(ref.id, {}) + self.assertEqual(rendered.strip(), result.strip()) + def test_if_from_body(self): t = self.env['ir.ui.view'].create({ 'name': 'test',