summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2013-12-16 14:42:59 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2013-12-16 14:42:59 -0800
commitdfb9674e5985bf9c781aa0c12eeac7acb5b597e2 (patch)
treea71c38b63a96d6dbde4677468f8264b49072f54f
parent975debc2cd459b9bfa80cfae10d2f090d3f1535a (diff)
downloadffi-yajl-dfb9674e5985bf9c781aa0c12eeac7acb5b597e2.tar.gz
add NaN + Infinity checking to Fixnum+Bignum
- this might not be necessary...
-rw-r--r--lib/ffi_yajl/ffi/encoder.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb
index 6e44796..f6aa122 100644
--- a/lib/ffi_yajl/ffi/encoder.rb
+++ b/lib/ffi_yajl/ffi/encoder.rb
@@ -104,8 +104,11 @@ end
class Fixnum
def ffi_yajl(yajl_gen, state)
+ str = self.to_s
+ if str == "NaN" || str == "Infinity" || str == "-Infinity"
+ raise ::FFI_Yajl::EncodeError.new("'#{str}' is an invalid number")
+ end
if state[:processing_key]
- str = self.to_s
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status)
end
@@ -120,6 +123,9 @@ end
class Bignum
def ffi_yajl(yajl_gen, state)
str = self.to_s
+ if str == "NaN" || str == "Infinity" || str == "-Infinity"
+ raise ::FFI_Yajl::EncodeError.new("'#{str}' is an invalid number")
+ end
if state[:processing_key]
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status)