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

Doctype entity parsing fails when run in strict mode #698

Open
6 of 7 tasks
jhulford opened this issue Dec 13, 2024 · 2 comments
Open
6 of 7 tasks

Doctype entity parsing fails when run in strict mode #698

jhulford opened this issue Dec 13, 2024 · 2 comments

Comments

@jhulford
Copy link
Contributor

  • Are you running the latest version?
  • 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 using fast-xml-parser in a browser and loading it as an esm module, when trying to parse an xml file that has a DOCTYPE with an entity in it, the DocTypeReader throws the reference error "entityName is not defined".

This can be recreated simply by adding "use strict"; to the top of the src/xmlparser/DocTypeReader.js file and running the projects unit tests. 5 tests will fail with the exact same error. VS Code will also highlight the problem variables.

The simple fix is to simply add let entityName, val; at line 23 of DocTypeReader.js

Input

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE note [
<!ENTITY nbsp "&#xA0;">
<!ENTITY writer "Writer: Donald Duck.">
<!ENTITY copyright "Copyright: W3Schools.">
]>

<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body attr="&writer;">Don't forget me this weekend!</body>
    <footer>&writer;&nbsp;&copyright;</footer>
</note> 

Code

const { XMLParser } = require('fast-xml-parser')
const options = {
  processEntities: true
}
// The following line will raise an error if run in strict mode
const result = new XMLParser(options)

Output

There should be no error and the entity should be processed correctly.

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

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.

@jhulford
Copy link
Contributor Author

I have submitted a PR that fixes the issue.

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