Skip to content

support nested CDATA #160

Closed
Closed
@fommil

Description

@fommil

according to https://en.wikipedia.org/wiki/CDATA#Nesting

A CDATA section cannot contain the string "]]>" and therefore it is not possible for a CDATA section to contain nested CDATA sections. The preferred approach to using CDATA sections for encoding text that contains the triad "]]>" is to use multiple CDATA sections by splitting each occurrence of the triad just before the ">". For example, to encode "]]>" one would write:
<![CDATA[]]]]><![CDATA[>]]>
This means that to encode "]]>" in the middle of a CDATA section, replace all occurrences of "]]>" with the following:
]]]]><![CDATA[>
This effectively stops and restarts the CDATA section.

It looks like we're not doing this in scala.xml, e.g.

      val top =
        """<?xml version="1.0" encoding="UTF-8"?>
          |<GRAND
          |    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vast.xsd" version="2.0">
          |    <Foo><![CDATA[%s]]></Foo>
          |</GRAND>""".stripMargin

      println(PCData(top).toString)

gives

<![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<GRAND
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vast.xsd" version="2.0">
    <Foo><![CDATA[%s]]></Foo>
</GRAND>]]>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions