diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2013-12-16 14:33:44 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2013-12-16 14:33:44 -0800 |
commit | 2cefbfbdf7217537b5a638a6dd697480e47d38d5 (patch) | |
tree | eae560d3c4864c57046614276cb9b3de7e41649a /ext/ffi_yajl/ext | |
parent | 58411ea2a9dc1e63150a3c4c496218d817d7cf9f (diff) | |
download | ffi-yajl-2cefbfbdf7217537b5a638a6dd697480e47d38d5.tar.gz |
fix encoding of fixnums and floats as keys
Diffstat (limited to 'ext/ffi_yajl/ext')
-rw-r--r-- | ext/ffi_yajl/ext/encoder/encoder.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/ext/ffi_yajl/ext/encoder/encoder.c b/ext/ffi_yajl/ext/encoder/encoder.c index f4999b8..da4ea17 100644 --- a/ext/ffi_yajl/ext/encoder/encoder.c +++ b/ext/ffi_yajl/ext/encoder/encoder.c @@ -136,7 +136,11 @@ static VALUE rb_cBignum_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { if (memcmp(cptr, "NaN", 3) == 0 || memcmp(cptr, "Infinity", 8) == 0 || memcmp(cptr, "-Infinity", 9) == 0) { rb_raise(cEncodeError, "'%s' is an invalid number", cptr); } - yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len); + if ( ((ffi_state_t *)state)->processing_key ) { + yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)cptr, len); + } else { + yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len); + } return Qnil; } @@ -148,7 +152,11 @@ static VALUE rb_cFloat_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { if (memcmp(cptr, "NaN", 3) == 0 || memcmp(cptr, "Infinity", 8) == 0 || memcmp(cptr, "-Infinity", 9) == 0) { rb_raise(cEncodeError, "'%s' is an invalid number", cptr); } - yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len); + if ( ((ffi_state_t *)state)->processing_key ) { + yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)cptr, len); + } else { + yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len); + } return Qnil; } |