fastify-xml-body-parser icon indicating copy to clipboard operation
fastify-xml-body-parser copied to clipboard

Parser converting number-like strings to numbers?

Open CaribouColin opened this issue 3 years ago • 1 comments

One of our endpoints accepts XML and parses it into a JS object. Part of the data that it receives includes a zip code. It appears that this parser is seeing what looks like a number and converting it into an int even though zip codes should be treated as strings. Is there a way to disable the automatic parsing of values?

UPDATE: I tried setting the attribute parsing value to false but it seems to be completely ignoring the option.

fastifyServer.register(require('fastify-xml-body-parser'), {
  parseAttributeValue: false,
})

Example Data:

<PostalCode>02108</PostalCode>
console.log(request.body); // { PostalCode: 2108 }

CaribouColin avatar Apr 18 '22 18:04 CaribouColin

@CaribouColin this package is using FXP v4 now. It means you can set numberparseoptions to manipulate the parsing result.

amitguptagwl avatar Apr 21 '22 01:04 amitguptagwl