[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.
This commit is contained in:
@@ -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', '<unknown>'),
|
||||
)
|
||||
|
||||
@@ -989,6 +989,43 @@ class TestQWebBasic(TransactionCase):
|
||||
self.assertEqual(html, """<root><span data-oe-type="text" data-oe-expression="text">a<br>
|
||||
b <b>c</b></span></root>""")
|
||||
|
||||
def test_out_markup(self):
|
||||
t = self.env['ir.ui.view'].create({
|
||||
'name': 'test',
|
||||
'type': 'qweb',
|
||||
'arch_db': '''<t t-name="esc-markup">
|
||||
<t t-set="content"><span>toto</span></t>
|
||||
<div t-out="content"/>
|
||||
</t>'''
|
||||
})
|
||||
result = """
|
||||
<div><span>toto</span></div>
|
||||
"""
|
||||
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': '''<t t-name="esc-markup">
|
||||
<t t-set="content"><span>toto</span></t>
|
||||
<div t-esc="content"/>
|
||||
</t>'''
|
||||
})
|
||||
ref = self.env['ir.ui.view'].create({
|
||||
'name': 'test',
|
||||
'type': 'qweb',
|
||||
'arch_db': '''<t t-name="esc-markup">
|
||||
<t t-set="content"><span>toto</span></t>
|
||||
<div t-out="content"/>
|
||||
</t>'''
|
||||
})
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user