[FIX] base: ir_qweb, allow to use link with xmlns
Until now, it is impossible to do <g:title>xxx</title> because qweb will autoclose the <g:link> because it checks if link is a void element instead to check g:link. Now we check the el_tag instead of unqualified_tag. closes odoo/odoo#159476 Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
This commit is contained in:
@@ -1317,7 +1317,7 @@ class IrQWeb(models.AbstractModel):
|
||||
|
||||
if unqualified_el_tag != 't':
|
||||
el.set('t-tag-open', el_tag)
|
||||
if unqualified_el_tag not in VOID_ELEMENTS:
|
||||
if el_tag not in VOID_ELEMENTS:
|
||||
el.set('t-tag-close', el_tag)
|
||||
|
||||
if not ({'t-out', 't-esc', 't-raw', 't-field'} & set(el.attrib)):
|
||||
@@ -1371,7 +1371,7 @@ class IrQWeb(models.AbstractModel):
|
||||
attributes = ''.join(f' {name}="{escape(str(value))}"'
|
||||
for name, value in attrib.items() if value or isinstance(value, str))
|
||||
self._append_text(f'<{el_tag}{"".join(attributes)}', compile_context)
|
||||
if unqualified_el_tag in VOID_ELEMENTS:
|
||||
if el_tag in VOID_ELEMENTS:
|
||||
self._append_text('/>', compile_context)
|
||||
else:
|
||||
self._append_text('>', compile_context)
|
||||
@@ -1386,7 +1386,7 @@ class IrQWeb(models.AbstractModel):
|
||||
body = self._compile_directive(el, compile_context, 'inner-content', level)
|
||||
|
||||
if unqualified_el_tag != 't':
|
||||
if unqualified_el_tag not in VOID_ELEMENTS:
|
||||
if el_tag not in VOID_ELEMENTS:
|
||||
self._append_text(f'</{el_tag}>', compile_context)
|
||||
|
||||
return body
|
||||
|
||||
@@ -670,6 +670,36 @@ class TestQWebNS(TransactionCase):
|
||||
with self.assertRaises(QWebException, msg=error_msg):
|
||||
self.env['ir.qweb']._render(view1.id)
|
||||
|
||||
|
||||
def test_render_static_xml_with_void_element(self):
|
||||
""" Test the rendering on a namespaced view with dynamic URI (need default namespace uri).
|
||||
"""
|
||||
tempate = """
|
||||
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
|
||||
<g:brand>Odoo</g:brand>
|
||||
<g:link>My Link</g:link>
|
||||
</rss>
|
||||
"""
|
||||
expected_result = """
|
||||
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
|
||||
<g:brand>Odoo</g:brand>
|
||||
<g:link>My Link</g:link>
|
||||
</rss>
|
||||
|
||||
"""
|
||||
|
||||
view1 = self.env['ir.ui.view'].create({
|
||||
'name': "dummy",
|
||||
'type': 'qweb',
|
||||
'arch': """
|
||||
<t t-name="base.dummy">%s</t>
|
||||
""" % tempate
|
||||
})
|
||||
|
||||
rendering = self.env['ir.qweb']._render(view1.id)
|
||||
|
||||
self.assertEqual(etree.fromstring(rendering), etree.fromstring(expected_result))
|
||||
|
||||
class TestQWebBasic(TransactionCase):
|
||||
def test_compile_expr(self):
|
||||
tests = [
|
||||
|
||||
Reference in New Issue
Block a user