oozcitak / xmlbuilder2

An XML builder for node.js
366 stars 36 forks source link

Some XML entities not decoded when converting to other formats #142

Closed pkmnfrk closed 1 year ago

pkmnfrk commented 2 years ago

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:

Nooxlock commented 2 years ago

Any update on this issue? Trying to find a temporary solution but with little to no success...

universalhandle commented 1 year ago

This looks like a duplicate of various issues that have been opened related to ampersand encoding (see #105, #109, #110). I believe this to be fixed with the release of v3.1.0. Please reopen if you can still reproduce after upgrading.