Skip to content

XMLSerializer incorrectly encodes non-breaking spaces in SVG as   #1918

@cubeghost

Description

@cubeghost

Describe the bug
XMLSerializer.serializeToString() converts non-breaking spaces in text nodes to  , which is not a named entity in XML.

To Reproduce

// the <tspan> here contains a non-breaking space
const document = new DOMParser().parseFromString('<body><svg viewBox="0 0 240 40" xmlns="http://www.w3.org/2000/svg"><text x="10" y="30" class="small">test<tspan> </tspan></text></svg></body>', 'text/html');
const svg = document.querySelector('svg');
const serializer = new XMLSerializer();
serializer.serializeToString(svg); // <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 40"><text x="10" y="30" class="small">test<tspan>&nbsp;</tspan></text></svg>

Expected behavior
Non-breaking spaces should be encoded as a numeric entity (&#160;) or left as-is

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions