xml-js icon indicating copy to clipboard operation
xml-js copied to clipboard

`attributeNameFn` callback receives an undefined attributeValue

Open ediblecode opened this issue 4 years ago • 0 comments

Repro steps:

Provide an attributeNameFn, where the second argument is an attributeValue as per the docs. For example:

xml2js(`<root><element attr="val">content</element></root>`, {
    attributeNameFn: (attributeName, attributeValue, parentElement) => {
        console.log({ attributeValue });

        return attributeName;
    },
});

Expected result

The received attributeValue argument is the value of the current attribute.

In the above example the expected result is logging { attributeValue: 'val' }.

Actual result

The received attributeValue argument in the attributeNameFn is undefined.

Further details

Looks like it's being caused by:

https://github.com/nashwaan/xml-js/blob/f0376f265c4f299100fb4766828ebf066a0edeec/lib/xml2js.js#L150-L154

Notice the value is being deleted before being passed into the function as the second argument. So passing temp here looks like it'd solve the issue.

ediblecode avatar Feb 04 '22 12:02 ediblecode