xmlbuilder2 icon indicating copy to clipboard operation
xmlbuilder2 copied to clipboard

Some XML entities not decoded when converting to other formats

Open pkmnfrk opened this issue 2 years ago • 0 comments

Describe the bug Entities like &, >, etc remain encoded when converting to eg object or json formats. Curiously, the quote entites (" and ') seem to translate fine

To Reproduce This is easy to reproduce during an interactive session:

> const create = require("xmlbuilder2").create;
undefined
> create("<test>&lt;test&gt;</test>").end({format: "json"});
'{"test":"&lt;test&gt;"}'
> create("<test>pb&amp;j</test>").end({format: "json"})
'{"test":"pb&amp;j"}'
> create("<test>&quot;double quotes&quot;</test>").end({format: "json"})
'{"test":"\\"double quotes\\""}'
> create("<test>&apos;single quotes&apos;</test>").end({format: "json"})
`{"test":"'single quotes'"}`

> create().ele("test").txt("pb&j").end({format: "xml"})
'<?xml version="1.0"?><test>pb&amp;j</test>'
> create(create().ele("test").txt("pb&j").end({format: "xml"})).end({format: "object"})
{ test: 'pb&amp;j' }

Expected behavior I expect &amp; to translate to &, &gt; to translate to >, etc

Version:

  • node.js: 14.17.1
  • xmlbuilder2: 3.0.2

pkmnfrk avatar Jun 15 '22 18:06 pkmnfrk