Skip to content

Invalid characters inside CDATA section #201

Open
@marcinar

Description

@marcinar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions