jPath for self-closing XML tag includes slash (original) (raw)
- Are you running the latest version? - yes, 4.2.2
- 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
jPath in updateTag() callback for self closing tag ends with /, which I doubt is intended.
Because of this, you need to check two different jPaths, with and without /, to accurately process tags that may be empty.
Input
bar ipsumCode
const skip = ["doc.foo"]; const parser = new XMLParser({ updateTag: (tagName, jPath) => { if (skip.includes(jPath)) { return false; } return tagName; }, });
Output
{ "doc": { "foo": "", "lorem": "ipsum" } }
expected data
{ "doc": { "lorem": "ipsum" } }
additional info
Code works if the skip array is changed to: ["doc.foo", "doc.foo/"] because for the self-closing tag jPath ends with /.
But I think that's easy to miss and not intended to be so? If you write code wanting to skip particular path and you don't test it with both self-closing and not-self closing tag you will be surprised.
Another workaround is to do:
updateTag: (tagName, jPath) => {
if (
skip.includes(jPath) ||
(jPath.endsWith("/") && skip.includes(jPath.slice(0, -1)))
) {
return false;
}
return tagName;
},Would you like to work on this issue?
- Yes
- No
Bookmark this repository for further updates. Visit SoloThought to know about recent features.