form-data: Error when trying to write boolean type
Hi, there,
We recently had this bug report https://github.com/request/request/issues/1693 in request
It turned out that the user passes a boolean
value to one of the form-data’s fields (field:false
) that results in _http_outgoing error in core.
My question is: Is the best place to fix that issue here, like you do for number
types?
// all that streamy business can't handle numbers
if (typeof value == 'number' || typeof value == 'boolean') value = ''+value;
About this issue
- Original URL
- State: open
- Created 9 years ago
- Comments: 18 (15 by maintainers)
The README still says that
boolean
is accepted and MDN still says thatFormData.set()
will convert to string. But this library still explodes, behaving differently than browsers are documented to. Since this is a polyfill to support running browser code outside of the browser, can it be updated to behave like the browser?Thanks.
I think it’s less about crashing in prod and more about it not being the expected result. Also where does JavaScript pass empty strings as false? Surely it’s falsy but Its not like its going to get casted to a Boolean before being sent out as form data.
Also what about consistency? If this is the thought we should just throw for everything that is not a string (excluding buffers and streams) including numbers. I think it would be great for core to have this restriction, but I think it would be best if user facing api’s simply casted to strings automatically. It has to be done at some point, it’s done in the browser, why shouldn’t we do it?
MDN says to cast to a string, but it also has other deprecated things. (But this does seem to be cross browser).
https://developer.mozilla.org/en-US/docs/Web/API/FormData/append#append()_Parameters
@alexindigo, I just checked how the browser formdata handles this and it does in fact cast booleans to strings. I think it would be generally convenient for node-form-data to do the same. Consumers of the formdata (another server) are going to have to cast some of the strings sent anyways so I think this makes sense.
What are your thoughts? Obviously I’m all for browser symmetry 👍.