Skip to content

Character data interpreted in XHTML #341

@Patrick-ring-motive

Description

@Patrick-ring-motive

script tags are interpreted as CDATA in typical html but in xhtml characters are interpreted using the standard syntax so for example, < and & are represented by &lt; and &amp;. You may think this is irrelevant in modern web because nobody uses xhtml but they do. Any time a script tag is nested inside an svg tag, it is interpreted as xhtml. See this example:

<script type="module">
    const gt = 5;
    const test = 5 &gt; + 7;
    console.log(+test); // > 5
</script>
<svg>
  <script type="module">
    const gt = 5;
    const test = 5 &gt; + 7;
    console.log(+test); // > 0
  </script>
</svg>

In the first script test is set to 5 & gt which is 5 & 5 resulting in 5. In the second script &gt; is converted to > so test is set to 5 > +7 which is false. Then +test is coerced into 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    new-exampleA proposal of the new example

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions