woodstox icon indicating copy to clipboard operation
woodstox copied to clipboard

Invalid characters inside CDATA section

Open marcinar opened this issue 3 months ago • 5 comments

Example:

var factory = XMLOutputFactory.newInstance();
factory.setProperty(WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER, new ReplacingHandler('�'));

try (var output = Files.newOutputStream(Paths.get("/tmp/test.xml"))) {
    XMLStreamWriter writer = factory.createXMLStreamWriter(output);

    writer.writeStartDocument();
    writer.writeStartElement("Test");
    writer.writeCData("Text content\u001A...");
    writer.writeEndElement();
    writer.writeEndDocument();

    writer.close();
}

In this case, the writer doesn't replace (or even check for) any invalid characters. The output contains the 0x1A codepoint inside the CDATA section, which isn't valid XML.

marcinar avatar Mar 20 '24 19:03 marcinar