Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When converting from xml string to js object, & might be double escaped #98

Closed
chuanqisun opened this issue Jul 20, 2021 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@chuanqisun
Copy link

chuanqisun commented Jul 20, 2021

Describe the bug

const { create } = require('xmlbuilder2');

const result = create(
  `<description>I'm &lt;b&gt;bold&lt;/b&gt;</description>`
).end({ format: 'object' });
console.log(result);
// Actual { description: "I'm &amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;" }
// Expected { description: "I'm <b>bold</b>" } Or { description: "I'm &lt;b&gt;bold&lt;/b&gt;" }

To Reproduce
https://stackblitz.com/edit/node-rmf2h7?devtoolsheight=33&file=index.js
run node index.js to produce output

Expected behavior
I might have misunderstood your design. I just thought the parser should either preserve the original string or unescape it.
Double escape the & seems to be strange behavior.

Version:

  • node.js: 14.16.0
  • xmlbuilder2 2.4.1

Additional context
I'm using your util to build the next major version of an RSS feed reader + generator. I'm following these examples to handle several html encoding scenarios. My primary use case is xml -> json but my tool will also handle feed generation so I really hope I can get the bi-directional conversion working with a single library. Thanks for the high quality work!

@chuanqisun chuanqisun added the bug Something isn't working label Jul 20, 2021
@chuanqisun
Copy link
Author

chuanqisun commented Jul 20, 2021

Might be related to #82 and #88. Feel free to close this as dupe if they are caused by the same issue.

@oozcitak
Copy link
Owner

Yes, this is a duplicate of #82 and #88. An interim fix might be to pass the noDoubleEncoding flag with end if that works for you. I'll fix this in the underlying DOM library: oozcitak/dom#7

@kernwig
Copy link

kernwig commented Jul 28, 2021

The noDoubleEncoding: true option had no effect for me when parsing XML text into Javascript object.

oozcitak added a commit to oozcitak/dom that referenced this issue Jul 29, 2021
oozcitak added a commit that referenced this issue Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants