Skip to content

Doctype entity parsing fails when run in strict mode #698

@jhulford

Description

@jhulford
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions