question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when trying to write boolean type

See original GitHub issue

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;

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:18 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
binkicommented, Jun 10, 2020

The README still says that boolean is accepted and MDN still says that FormData.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.

1reaction
DylanPierceycommented, Jul 28, 2015

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - How to fix "this method must return boolean type" error
The obvious error is that your method does not return anything when count is non-zero. You don't even need a conditional for it...
Read more >
[Solved] How do I fix this bool code? - CodeProject
If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are...
Read more >
ADF throws an error while using boolean variables in ...
Your variables in Master pipeline are declared as Boolean type already. Hence you no need to convert them again to bool using bool()...
Read more >
5-1 Boolean expressions
computer programming, one only takes one kind of test: a boolean test — true or ... Your first instinct might be to write...
Read more >
C# Booleans - W3Schools
For this, C# has a bool data type, which can take the values true or false . Boolean Values. A boolean type is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found