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

HTML Ampersand entity (&) is replaced with the ampersand symbol (&) when parsing #702

Open
6 of 7 tasks
aureliomarcoag opened this issue Jan 2, 2025 · 2 comments
Open
6 of 7 tasks

Comments

@aureliomarcoag
Copy link

  • Are you running the latest version? Yes, 4.5.1
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool?
  • Have you checked the docs for helpful APIs and examples?

Description

When parsing an XML node with an attribute that contains HTML-escaped symbols, the ampersand & symbol is parsed, but others aren't.

Input

<?xml version="1.0"?>
<node attr="some value with ampersand &amp; and other HTML symbols like &commat; and &equals;">
</node>

Code

import { XMLParser } from 'fast-xml-parser';
const parser = new XMLParser({ ignoreAttributes: false });
const raw = `<?xml version="1.0"?>
<node attr="some value with ampersand &amp; and other HTML symbols like &commat; and &equals;">
</node>`;
console.log(parser.parse(raw));

Output

The ampersand HTML entity is replaced with the actual Ampersand symbol, but other symbols such as @ and = aren't.

{
  '?xml': { '@_version': '1.0' },
  node: {
    '@_attr': 'some value with ampersand & and other HTML symbols like &commat; and &equals;'
  }
}

expected data

No HTML entity should be parsed at all, and the attribute value should contain &amp; instead of &.

{
  '?xml': { '@_version': '1.0' },
  node: {
    '@_attr': 'some value with ampersand &amp; and other HTML symbols like &commat; and &equals;'
  }
}

Would you like to work on this issue?

  • Yes
  • No

Bookmark this repository for further updates. Visit SoloThought to know about recent features.

Copy link

github-actions bot commented Jan 2, 2025

We're glad you find this project helpful. We'll try to address this issue ASAP. You can vist https://solothought.com to know recent features. Don't forget to star this repo.

@aureliomarcoag
Copy link
Author

Oh my bad, it seems the XML spec also specifies an &amp; entity and this behavior would therefore be correct. Please confirm and if so, feel free to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant