Skip to content

Commit

Permalink
Fix encoding uncommon types
Browse files Browse the repository at this point in the history
  • Loading branch information
nateberkopec committed Nov 21, 2014
1 parent f4e269c commit e11af01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/raven/okjson.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def valenc(x)
when false then "false"
when nil then "null"
else
raise Error, "cannot encode #{x.class}: #{x.inspect}"
strenc((x.inspect rescue $!.to_s))
end
end

Expand Down
9 changes: 9 additions & 0 deletions spec/raven/okjson_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
end
end

it 'encodes anything that responds to to_s' do
data = [
Date.new(2014),
Rational(1),
(1..5)
]
expect(Raven::OkJson.encode(data)).to eq '["#<Date: 2014-01-01 ((2456659j,0s,0n),+0s,2299161j)>",1/1,"1..5"]'
end

it 'parses zero-leading exponent numbers correctly' do
expect(Raven::OkJson.decode("[123e090]")).to eq [123000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000]
end
Expand Down

0 comments on commit e11af01

Please sign in to comment.