Skip to content

unpairedTags option does not work correctly with text nodes #609

@mohd-akram

Description

@mohd-akram
  • 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 unpairedTags option does not seem to behave correctly with text nodes.

Input

Code

const assert = require('assert/strict');

const { XMLParser, XMLBuilder } = require('fast-xml-parser');

const html = '<div>1<br>2<br></div>';
console.log(html);

const parsingOptions = {
  preserveOrder: true,
  unpairedTags: ['br'],
};
const parser = new XMLParser(parsingOptions);
const result = parser.parse(html);
console.log(JSON.stringify(result, null, 2));

const builderOptions = {
  preserveOrder: true,
  unpairedTags: ['br'],
}
const builder = new XMLBuilder(builderOptions);
const output = builder.build(result);
console.log(output);

assert.equal(output, html);

Output

[
  {
    "div": [
      {
        "#text": 1
      },
      {
        "br": [
          {
            "#text": 2
          }
        ]
      },
      {
        "br": []
      }
    ]
  }
]
<div>1<br><br></div>

expected data

[
  {
    "div": [
      {
        "#text": 1
      },
      {
        "br": []
      },
      {
        "#text": 2
      },
      {
        "br": []
      }
    ]
  }
]
<div>1<br>2<br></div>

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

    PendingPending to be confirmed by user/author for some check/update/implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions