summaryrefslogtreecommitdiff
path: root/addons/web/static/lib
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2020-02-21 09:46:12 +0000
committerLucas Perais (lpe) <lpe@odoo.com>2020-02-24 15:32:19 +0000
commit9256492f105719df2756524a10e0659c991bb810 (patch)
tree1b9a370b550449105ab5df2e5df5235cdf8e0561 /addons/web/static/lib
parent0e77b3d16a2e1e980deae3c3ea06ed44c3536d28 (diff)
[FIX] qweb2: ignore comments between branching directives
Have a template of that form: ```xml <t t-if=""/> <!-- Comment --> <t t-elif=""/> ``` Before this commit, both python and JS crashed because any type of node between branching directive was forbidden After this commit, Comments are just ignored and removed, while actual template nodes are still forbidden between branching directives There is no crash anymore closes odoo/odoo#45899 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Diffstat (limited to 'addons/web/static/lib')
-rw-r--r--addons/web/static/lib/qweb/qweb-test-conditionals.xml27
-rw-r--r--addons/web/static/lib/qweb/qweb2.js2
2 files changed, 28 insertions, 1 deletions
diff --git a/addons/web/static/lib/qweb/qweb-test-conditionals.xml b/addons/web/static/lib/qweb/qweb-test-conditionals.xml
index e754298a4aa..f4b95b697da 100644
--- a/addons/web/static/lib/qweb/qweb-test-conditionals.xml
+++ b/addons/web/static/lib/qweb/qweb-test-conditionals.xml
@@ -38,4 +38,31 @@
</t>
<params id="boolean-value-condition-false-else">{"condition": false}</params>
<result id="boolean-value-condition-false-else"><![CDATA[<div><span>begin</span>fail-else<span>end</span></div>]]></result>
+
+ <t t-name="comment-branching">
+ <t t-if="condition == 'if'">if</t>
+ <t t-elif="condition == 'elif1'">elif1</t>
+ <!-- Comment ignored PART OF THE TEST !!! -->
+ <t t-elif="condition == 'elif2'">elif2</t>
+ <t t-else="">else</t>
+ </t>
+ <params id="comment-branching">{"condition": "elif1"}</params>
+ <result id="comment-branching"><![CDATA[elif1]]></result>
+
+ <t t-name="comment-branching-1">
+ <t t-if="condition == 'if'">if</t>
+ <t t-elif="condition == 'elif1'">elif1</t>
+ <!-- Comment ignored PART OF THE TEST !!! -->
+ <t t-elif="condition == 'elif2'">elif2</t>
+ <t t-else="">else</t>
+ </t>
+ <params id="comment-branching-1">{"condition": "elif2"}</params>
+ <result id="comment-branching-1"><![CDATA[elif2]]></result>
+
+ <t t-name="comment-branching-2">
+ <div t-if="condition == 'if'">if</div><!-- Comment ignored PART OF THE TEST !!! --><div>sometext</div>
+ </t>
+ <params id="comment-branching-2">{"condition": "if"}</params>
+ <result id="comment-branching-2"><![CDATA[<div>if</div><div>sometext</div>]]></result>
+
</templates>
diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js
index 5126138bc36..2cfd2286cbc 100644
--- a/addons/web/static/lib/qweb/qweb2.js
+++ b/addons/web/static/lib/qweb/qweb2.js
@@ -327,7 +327,7 @@ QWeb2.Engine = (function() {
// All text nodes between branch nodes are removed
var text_node;
while ((text_node = node.previousSibling) !== prev_elem) {
- if (self.tools.trim(text_node.nodeValue)) {
+ if (text_node.nodeType !== 8 && self.tools.trim(text_node.nodeValue)) {
return self.tools.exception("Error: text is not allowed between branching directives");
}
// IE <= 11.0 doesn't support ChildNode.remove