You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:marshal() passes the comments among the child elements to fast-xml-builder as elements named #comment or #comment0, #comment1 and so on, and turns them into comments afterwards with a regular expression, because the builder's keyed-object mode can hold only one comment key per element. Their text is therefore escaped like element text: <!-- a & <b> --> is written back as <!-- a & <b> -->, and a carriage return becomes . The comments before the root element are added to the output string without any check, so a comment that an application sets with -- or --> in it gives a document that is not well-formed or contains injected markup. The fix is to build the tree in the builder's ordered mode (preserveOrder: true), with comments, the XML declaration and the comments before the root as entries of their own, and to throw an error for a comment that contains -- or ends with -, because XML cannot represent it.
Activity
Decode character references (#287)
neumaennl commentedon Nov 10, 2026
Upstream issues related to this fix:
preserveOrder: truewithformat: true: output starts with a line break and has none at the end — intended? NaturalIntelligence/fast-xml-builder#30: withpreserveOrder: trueandformat: true, the output starts with a line break and has none at the end. After the switch to the ordered mode,marshal()accepts this instead of working around it.preserveOrder: truewithformat: trueformats mixed content wrongly and adds whitespace to content that ends with>NaturalIntelligence/fast-xml-builder#31: the ordered mode formats mixed content wrongly and adds whitespace to content that ends with>. Fix: fix: format content by its child entries, not by the string NaturalIntelligence/fast-xml-builder#32.