Closed yykamei closed 1 year ago
Great catch @yykamei, I think you spot a valid bug.
I had a quick look and yes, according to the JSON specification true
or false
are valid JSON payloads like any other scalar value (like a single string or number).
So false
should be encoded into "false"
as you'd expect.
There's also the extreme edge-case scenario where you might want to send a plain null
value, which is interestingly also a valid JSON! But we can leave that for another day 😄
Would you have some time to open a PR to fix the false
edge case and add some tests?
Thank you for your reply! I'll do that 💪
There's also the extreme edge-case scenario where you might want to send a plain
null
value, which is interestingly also a valid JSON! But we can leave that for another day 😄
Yes, I agree with you. there could be null
body. I guess there could be programs that make the payload by putting nil
to env[:body]
, so I will keep it as is.
Basic Info
Issue description
Faraday::Request::Json
doesn't encode the valuefalse
while it encodestrue
to"true"
. I thinkfalse
is a valid JSON value, so the Faraday middleware should encodefalse
to"false"
.The reason why
false
is not encoded is the code below returnsfalse
after evaluating(body = env[:body])
, which isfalse
becauseenv[:body]
isfalse
.https://github.com/lostisland/faraday/blob/111d354b7f232f6bc3292e4cde6d08d2b983e9ae/lib/faraday/request/json.rb#L43
Steps to reproduce
./bin/setup
./bin/console
Then, IRB gives you
false
, not"false"
.By the way, you can get
"true"
with this code: