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

Error: Invalid character entity when use !ENTITY #443

Closed
japroc opened this issue Apr 8, 2018 · 3 comments
Closed

Error: Invalid character entity when use !ENTITY #443

japroc opened this issue Apr 8, 2018 · 3 comments

Comments

@japroc
Copy link

japroc commented Apr 8, 2018

Is it possible to parse the following code, or any which uses External Entities using parseString function?
capture
It always output errors like this

Error: Invalid character entity
Line: ...
Column: 57
Char: ;
@japroc japroc closed this as completed Apr 9, 2018
@julimen5ml
Copy link

Hi @Yookkee, did you find a way to escape that error?

@jcsahnwaldt
Copy link
Contributor

sax-js ignores custom DTD <!ENTITY ...> definitions: "It's possible to define additional entities in XML by putting them in the DTD. This parser doesn't do anything with that." https://github.com/isaacs/sax-js#regarding-doctypes-and-entitys Thus when a custom entity like &xxe; occurs in the XML, the parser throws an error.

@jcsahnwaldt
Copy link
Contributor

jcsahnwaldt commented Jun 12, 2018

Here's an ugly workaround:

let parser = new xml2js.Parser();
parser.saxParser.ENTITIES.xxe = 'whatever';
parser.parseString('<foo>&xx;</foo>', (err, res) => {
  if (err) console.log(err);
  else console.log(res);
});

Result:

{ foo: 'whatever' }

You shouldn't use this in production code though. parser.saxParser and saxParser.ENTITIES are undocumented properties that may go away any moment. (Well, in any minor version upgrade.)

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

3 participants