tinyxml2
tinyxml2 copied to clipboard
CDATA output containing ]]> is not well-formed XML
On master 8224e42, writing the text a]]>b in CDATA mode produces <r><![CDATA[a]]>b]]></r>. The embedded ]]> closes the CDATA section early and the remaining ]]> is invalid character data. Python's xml.etree parser rejects the output. Normal-text mode writes <r>a]]>b</r> and round-trips the original value.
This occurs both with XMLDocument::NewText("a]]>b") followed by SetCData(true) and with XMLPrinter::PushText("a]]>b", true). XMLPrinter::PushText writes the value directly between the CDATA delimiters. Would splitting the value across adjacent CDATA sections be an acceptable fix? That can preserve the text while producing valid XML. AI-assisted investigation and reproduction.