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

Incorrect parsing entity < #501

Closed
5 of 6 tasks
AllanZhengYP opened this issue Sep 29, 2022 · 1 comment
Closed
5 of 6 tasks

Incorrect parsing entity < #501

AllanZhengYP opened this issue Sep 29, 2022 · 1 comment
Labels

Comments

@AllanZhengYP
Copy link

AllanZhengYP commented Sep 29, 2022

  • 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?

Description

The predefined entity seems to be parsed twice. &amp;lt; is expected to be parsed to $lt;. However, it is parsed again to <

Input

<SimpleScalarPropertiesInputOutput>
  <stringValue>&amp;lt;</stringValue>
</SimpleScalarPropertiesInputOutput>

Code

import { XMLParser } from "fast-xml-parser";

const encoded = `<SimpleScalarPropertiesInputOutput>
  <stringValue>&amp;lt;</stringValue>
</SimpleScalarPropertiesInputOutput>`;
const parser = new XMLParser({})
const parsed = parser.parse(encoded);

console.log(JSON.stringify(parsed, null, 2));

Output

{
  "SimpleScalarPropertiesInputOutput": {
    "stringValue": "<"
  }
}

expected data

{
  "SimpleScalarPropertiesInputOutput": {
    "stringValue": "&lt;"
  }
}

Would you like to work on this issue?

  • Yes
  • No
    If with sufficient guidance.

It seems to be caused by replacing the escaped value with entity regex in a loop:

for(let entityName in this.lastEntities){
const entity = this.lastEntities[entityName];
val = val.replace( entity.regex, entity.val);
}

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

No branches or pull requests

2 participants