Skip to content

Incorrect parsing entity < #501

@AllanZhengYP

Description

@AllanZhengYP
  • 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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions