Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.88k stars 604 forks source link

charkey cannot match name of child node #655

Open scottwillman opened 1 year ago

scottwillman commented 1 year ago

It appears that if the charkey matches the name of a child node the return value breaks in a very interesting way. Took me a while to figure out what was going on.

In this example:

const test = `
    <meters>
        <meter>
            <key>engine</key>
            <value>1747</value>
            <units>hrs</units>
        </meter>
    </meters>`;

With these options:

await xml2js.parseStringPromise(test, {
    explicitArray: false,
    charkey: 'value',
});

Produces this result:

{
    "meters": {
        "meter": {
            "value": "\n            \n            ,1747\n            \n        ",
            "key": "engine",
            "units": "hrs"
        }
    }
}

I'm not exactly sure what the right behaviour is here, but possibly worth warning in the docs.