[FIX] base: support tail text after a comment
This commit fixes the case where you have some text after a comment.
Until know, we miss it. Now we render the tail part.
```
<t>
<!-- HIDE Text 1 -->
Text 1
<p>SHOW Text 2</p>
</t>
```
After the fix, Text 1 is correctly rendered
This commit fixes #76628
closes odoo/odoo#78782
X-original-commit: 566360b07b4ff6c7290f264d9064400df2b06ca5
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
@@ -939,10 +939,9 @@ class QWeb(object):
|
||||
body = []
|
||||
if el.getchildren():
|
||||
for item in el:
|
||||
# ignore comments & processing instructions
|
||||
if isinstance(item, etree._Comment):
|
||||
continue
|
||||
body.extend(self._compile_node(item, options, indent))
|
||||
if not isinstance(item, etree._Comment):
|
||||
body.extend(self._compile_node(item, options, indent))
|
||||
# comments can also contains tail text
|
||||
if item.tail is not None:
|
||||
self._appendText(item.tail, options)
|
||||
return body
|
||||
|
||||
@@ -5,6 +5,7 @@ import collections
|
||||
import json
|
||||
import os.path
|
||||
import re
|
||||
import markupsafe
|
||||
|
||||
from lxml import etree, html
|
||||
from lxml.builder import E
|
||||
@@ -1262,3 +1263,26 @@ class TestEmptyLines(TransactionCase):
|
||||
self.assertTrue(re.compile('^\s+\n').match(rendered))
|
||||
self.assertTrue(re.compile('\n\s+\n').match(rendered))
|
||||
|
||||
|
||||
class TestQWebMisc(TransactionCase):
|
||||
def test_render_comment_tail(self):
|
||||
""" Test the rendering of a tail text, near a comment.
|
||||
"""
|
||||
|
||||
view1 = self.env['ir.ui.view'].create({
|
||||
'name': "dummy",
|
||||
'type': "qweb",
|
||||
'arch': """
|
||||
<t>
|
||||
<!-- it is a comment -->
|
||||
<!-- it is another comment -->
|
||||
Text 1
|
||||
<!-- it is still another comment -->
|
||||
Text 2
|
||||
<t>ok</t>
|
||||
</t>
|
||||
"""
|
||||
})
|
||||
emptyline = '\n '
|
||||
expected = markupsafe.Markup('Text 1' + emptyline + 'Text 2' + emptyline + 'ok')
|
||||
self.assertEqual(view1._render(), expected)
|
||||
|
||||
Reference in New Issue
Block a user