Skip to content

Upgrading from 3.0.1 to 3.0.2 un-escapes & #117

Open
@benasher44

Description

@benasher44

Describe the bug
We're encoding some HTML into an XML document. The HTML has an already encoded &. Going from 3.0.1 to 3.0.2, this sequence is encoded back into a & instead of being left as &amp.

To Reproduce

const html = `<ul style="min-height:1.5em"><li><p style="min-height:1.5em">Peanut butter &amp; jelly.<br /></p></li></ul><p style="min-height:1.5em"><strong>Heading:</strong><br /></p><ul style="min-height:1.5em"><li><p style="min-height:1.5em">list item.</p></li><li><p style="min-height:1.5em">list item; more.</p></li><li><p style="min-height:1.5em">list item.</p></li><li><p style="min-height:1.5em">list item.</p></li><li><p style="min-height:1.5em">list item.</p></li><li><p style="min-height:1.5em">list item.<br /></p></li></ul>`;
const xml = create({ encoding: "utf-8", version: "1.0" }, { test: html }).end({
  prettyPrint: true,
});

Expected behavior
We expect the following XML (3.0.1):

<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
      <test>&lt;ul style=\\"min-height:1.5em\\"&gt;&lt;li&gt;&lt;p style=\\"min-height:1.5em\\"&gt;Peanut butter &amp; jelly.&lt;br /&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=\\"min-height:1.5em\\"&gt;&lt;strong&gt;Heading:&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;ul style=\\"min-height:1.5em\\"&gt;&lt;li&gt;&lt;p style=\\"min-height:1.5em\\"&gt;list item.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=\\"min-height:1.5em\\"&gt;list item; more.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=\\"min-height:1.5em\\"&gt;list item.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=\\"min-height:1.5em\\"&gt;list item.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=\\"min-height:1.5em\\"&gt;list item.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=\\"min-height:1.5em\\"&gt;list item.&lt;br /&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</test>

We're getting this, instead (3.0.2):

<test>&lt;ul style="min-height:1.5em"&gt;&lt;li&gt;&lt;p style="min-height:1.5em"&gt;Peanut butter & jelly.&lt;br /&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style="min-height:1.5em"&gt;&lt;strong&gt;Heading:&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;ul style="min-height:1.5em"&gt;&lt;li&gt;&lt;p style="min-height:1.5em"&gt;list item.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style="min-height:1.5em"&gt;list item; more.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style="min-height:1.5em"&gt;list item.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style="min-height:1.5em"&gt;list item.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style="min-height:1.5em"&gt;list item.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style="min-height:1.5em"&gt;list item.&lt;br /&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</test>

The only difference is that first &amp; is now a &, making the XML document invalid. Picture to highlight differences:

Screen Shot 2022-01-25 at 10 43 10 AM

Version:

  • node.js: 16.13.0
  • xmlbuilder2 3.0.2

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions