Self-closing <mutation> tag in XML will break the resulting 'if' block
See original GitHub issueDescribe the bug
If you provide toolbox XML with a self-closing mutation tag, the resulting ‘if’ block will be malformed.
To Reproduce
The easiest way to reproduce this is to apply this patch to the repo:
diff --git a/tests/playground.html b/tests/playground.html
index 3523caa6..6a07c912 100644
--- a/tests/playground.html
+++ b/tests/playground.html
@@ -692,6 +692,16 @@ var spaghettiXml = [
<block type="logic_null" disabled="true"></block>
<block type="logic_ternary"></block>
</category>
+ <category name="Test" categorystyle="logic_category">
+ <block type="controls_if">
+ <mutation else="1"/>
+ <value name="IF0">
+ <block type="logic_boolean">
+ <field name="BOOL">TRUE</field>
+ </block>
+ </value>
+ </block>
+ </category>
<category name="Loops" categorystyle="loop_category">
<block type="controls_repeat_ext">
<value name="TIMES">
Then, open blockly/tests/playground.html
in the browser and click “Test” in the toolbox.
Expected: this screenshot that properly has the contents of the ‘if’ block:
Actual outcome: this screenshot which shows a blank ‘if’ block:
Desktop:
- OS: Windows 10
- Browser: Chrome 79.0.3945.117, Firefox 72.0.1, and Safari 13.0.4 (15608.4.9.1.3) (i.e. I don’t think this is browser- or OS-dependent)
Stack Traces
There is no error message in the console for this.
Additional context
I investigated for quite a while, but I can’t definitively say what the problem is. What I did notice is that domToBlockHeadless_
won’t form any connections between blocks when the XML includes the self-closing tag.
Note that Blockly generates XML with self-closing mutation tags, which is the only way I even discovered this bug since I tried using my workspace’s XML as a toolbox:
-
Configure an ‘if’ block with an ‘else’ mutation:
-
Click “Export to XML”:
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (7 by maintainers)
Top GitHub Comments
The issue with the block in the toolbox is that modern HTML does not permit self-closing tags and so the block xml:
Is treated as though it was:
and so when html element is parsed, we lose the boolean value because it is nested inside the mutation element instead of being a direct child of the block element. This can be observed by inspecting the html. Technically, self-closing mutation tag does work if it is after the value, but otherwise there is an issue.
Great job, everyone! Thanks for the quick turnaround time. 😄