`attributesGroupName` writes `null` and `undefined` attribute values as text
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 83/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
- Domain
- backend
Research direction
Start in src/fxb.js, comparing the individually keyed attribute handling around lines 170–183 with the attributesGroupName branch around lines 281–288. Check the existing tests for grouped attributes and add coverage for null and undefined values. Done means grouped and individually keyed attributes both omit those values and the remaining attribute output matches the expected XML.
Written by the indexing model from the issue text.
Description
Summary
Version: 1.3.2
Context: I group attributes so that attribute keys don't need the @_ prefix and can't collide with child element names.
With attributesGroupName set, an attribute whose value is null or undefined is written as the text "null" or "undefined". Without a group name, the same values are left out.
Reproduction
import XMLBuilder from 'fast-xml-builder';
const perKey = new XMLBuilder({ ignoreAttributes: false });
console.log(perKey.build({ item: { '@_a': 'x', '@_b': null, '@_c': undefined } }));
// <item a="x"></item>
const grouped = new XMLBuilder({ ignoreAttributes: false, attributesGroupName: '$' });
console.log(grouped.build({ item: { $: { a: 'x', b: null, c: undefined } } }));
// <item a="x" b="null" c="undefined"></item>
Expected
Both print <item a="x"></item>.
Additional details
When building, the builder skips undefined and null values for individually keyed attributes (src/fxb.js#L170-L183), which came from NaturalIntelligence/fast-xml-parser#598 for NaturalIntelligence/fast-xml-parser#585. The attributesGroupName branch (src/fxb.js#L281-L288) passes every value in the group to buildAttrPairStr without that check. attributeValueProcessor can't drop an attribute, so no option works around it.
- Dominant language
- JavaScript
- Stars
- 22
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NaturalIntelligence/fast-xml-builder
-
`preserveOrder: true` with `format: true` formats mixed content wrongly and adds whitespace to content that ends with `>`Possibly taken @neumaennl claimed this 8 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
`XMLBuilder` object should be exported as a named export, not just the typePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
NaturalIntelligence/fast-xml-builder#25 · 1 comment ·
-
sanitizeName not applied to names inside stopNodes (quote injection / tag break-out bypass)Possibly taken @hicay claimed this 5 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
NaturalIntelligence/fast-xml-builder#34 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 54/100
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 48/100
NaturalIntelligence/fast-xml-builder#4 · 5 comments · 2 reactions ·
All issues in NaturalIntelligence/fast-xml-builder
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
Extended search drops any query term that contains a line breakPossibly taken @goranai claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
area:mcp
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day