question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Self-closing <mutation> tag in XML will break the resulting 'if' block

See original GitHub issue

Describe 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: image

Actual outcome: this screenshot which shows a blank ‘if’ block: image

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:

  1. Configure an ‘if’ block with an ‘else’ mutation: image

  2. Click “Export to XML”:

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
moniikacommented, Jan 27, 2020

The issue with the block in the toolbox is that modern HTML does not permit self-closing tags and so the block xml:

<block type="controls_if">
  <mutation else="1"/>
    <value name="IF0">
    <block type="logic_boolean">
      <field name="BOOL">TRUE</field>
    </block>
  </value>
</block>

Is treated as though it was:

<block type="controls_if">
  <mutation else="1">
    <value name="IF0">
    <block type="logic_boolean">
      <field name="BOOL">TRUE</field>
    </block>
    </value>
  </mutation>
</block>

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.

0reactions
Adam13531commented, Jan 27, 2020

Great job, everyone! Thanks for the quick turnaround time. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript breaks when reading a self closing tag in XML
The script breaks and stops when it reaches a self closing tag. What do I need to do to get it either output...
Read more >
HTML 5.1: 8. The HTML syntax - W3C
Foreign elements whose start tag is not marked as self-closing can have text, character references, CDATA sections, other elements, and comments ...
Read more >
4 XML Parsing for Java - Oracle Help Center
Prerequisites. Oracle XML parsing reads an XML document and uses DOM or SAX APIs to provide programmatic access to its content and structure....
Read more >
Practical guide to XHTML - Project Nayuki
XHTML is a modified version of HTML that obeys XML syntax strictly. ... Either self-closing or no end tag: ... Comment blocks. Can...
Read more >
Google JavaScript Style Guide
A JavaScript source file is described as being in Google Style if and only if ... Line break after the closing brace if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found