From e4548204d16e64e3c8de7722e6c4cadaf5684098 Mon Sep 17 00:00:00 2001 From: Al Tenhundfeld Date: Sat, 6 Jun 2015 14:11:44 -0400 Subject: [PATCH] Change okjson to encode NaN and Infinity as string, instead of raising error. --- lib/raven/okjson.rb | 2 +- spec/raven/okjson_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/raven/okjson.rb b/lib/raven/okjson.rb index 2fda91719..64c79268b 100644 --- a/lib/raven/okjson.rb +++ b/lib/raven/okjson.rb @@ -499,7 +499,7 @@ def strenc(s) def numenc(x) if ((x.nan? || x.infinite?) rescue false) - raise Error, "Numeric cannot be represented: #{x}" + return strenc(x.to_s) end "#{x}" end diff --git a/spec/raven/okjson_spec.rb b/spec/raven/okjson_spec.rb index b88fdc844..138041107 100644 --- a/spec/raven/okjson_spec.rb +++ b/spec/raven/okjson_spec.rb @@ -23,9 +23,11 @@ it 'encodes anything that responds to to_s' do data = [ (1..5), - :symbol + :symbol, + 1/0.0, + 0/0.0 ] - expect(Raven::OkJson.encode(data)).to eq "[\"1..5\",\"symbol\"]" + expect(Raven::OkJson.encode(data)).to eq "[\"1..5\",\"symbol\",\"Infinity\",\"NaN\"]" end it 'does not parse scientific notation' do