mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
fix default json encoder: encode nil to null
This commit is contained in:
parent
aa595b3217
commit
c9d3f718e6
2 changed files with 4 additions and 3 deletions
|
@ -100,7 +100,8 @@ module Sinatra
|
|||
fail "invalid: #{o.inspect}" unless a.empty? or a.include? o.class
|
||||
case o
|
||||
when Float then o.nan? || o.infinite? ? 'null' : o.inspect
|
||||
when TrueClass, FalseClass, NilClass, Numeric, String then o.inspect
|
||||
when TrueClass, FalseClass, Numeric, String then o.inspect
|
||||
when NilClass then 'null'
|
||||
when Array then map(o, "[%s]") { |e| enc(e) }
|
||||
when Hash then map(o, "{%s}") { |k,v| enc(k, String) + ":" + enc(v) }
|
||||
end
|
||||
|
|
|
@ -41,8 +41,8 @@ describe Sinatra::JSON do
|
|||
end
|
||||
|
||||
it "encodes objects to json out of the box" do
|
||||
mock_app { get('/') { json :foo => [1, 'bar'] } }
|
||||
results_in 'foo' => [1, 'bar']
|
||||
mock_app { get('/') { json :foo => [1, 'bar', nil] } }
|
||||
results_in 'foo' => [1, 'bar', nil]
|
||||
end
|
||||
|
||||
it "sets the content type to 'application/json'" do
|
||||
|
|
Loading…
Reference in a new issue