Skip to content

Inconsistent parsing for namespaced tags with boolean attributes allowed #320

@CamilleDrapier

Description

@CamilleDrapier
  • 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

It seems like something in the recent version (3.16.0 seems to not have this problem) changed the behavior of the parsing for namespaced tags with no attributes. Until now these would be parsed as simple strings, but recently they are parsed as objects. Apparently, from the change-log, this was not an intended change.

Input

This can be reproduced in the online tool by using the following input

<example>This is a test</example>
<ns1:otherexample>This is another test</ns1:otherexample>

And only selecting these options:

  • Remove namespace string from tag and attribute names.
  • Allow Boolean Attributes

Un-selecting either of them gives an expected output.

Code

var xml = "<example>This is a test</example><ns1:otherexample>This is another test</ns1:otherexample>"
parser.parse(xml, {
    ignoreNameSpace: true,
    allowBooleanAttributes: true,
    ignoreAttributes: false,
  });

Output

{
    "example": "This is a test",
    "otherexample": {
        "#text": "This is another test",
        "@_otherexample": true
    }
}

expected data

{
    "example": "This is a test",
    "otherexample": "This is another test"
}

Would you like to work on this issue?

  • Yes
  • No

Bookmark this repository for further updates.

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