Skip to content

Incorrect serialization of XML attributes containing white space #284

Description

@marrus-sh

The code for serializing attributes (here:

xmldom/lib/dom.js

Lines 1138 to 1140 in 6ce4700

function addSerializedAttribute(buf, qualifiedName, value) {
buf.push(' ', qualifiedName, '="', value.replace(/[<&"]/g,_xmlEncoder), '"')
}
) does not treat newlines in any special way.

This is a problem, because XML parses literal newlines as spaces. However, it allows newlines in attributes when they are provided as character references. (See: https://www.w3.org/TR/xml/#AVNormalize.)

So:

<element attribute="with&#xA;newline"></element>

serializes as

<element attribute="with
newline"></element>

which then gets parsed as

<element attribute="with newline"></element>

which is not equivalent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeSome thing that requires a version bump due to breaking changesspec:DOM-Parsingspec:XMLhttps://www.w3.org/TR/xml11/

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions