oj 2.7.1 → 2.7.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oj might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d543163764b5c7910fcbd77662a531acb56d8cff
4
- data.tar.gz: f9c6554f24fc5ccf9ea95b755e009ddfbd603567
3
+ metadata.gz: f30913f8e7b9a96cd9388dcd6959330f34960c04
4
+ data.tar.gz: 8bb5882a6def1fbb9348f0ac0a48f59d1d7468f4
5
5
  SHA512:
6
- metadata.gz: b4363a5dab53fe54977632c92caec3a77e304893a70230066dfc3332c81b570e82715140330e4affcb0e69f6094c108b563675873bdd1896a667fa757d6f8249
7
- data.tar.gz: 4c7cdfcb15522a3ced05947997f31e30d2a55b2386456ea2279eb48852cbac08b8bd6378115b2f835beea264c0aea34d616c2d0ad2d7d5257506526d36fcb7ed
6
+ metadata.gz: 70e9ec5a16483c18e964d2ab4f8801c111353018fef608fc035de8bbd19b855baf825659e55a1af11a0ed9795902316517a27ad58b82cc05b81773f5678a434a
7
+ data.tar.gz: c9f605979c2b2051a8257fcb57a125aa3b5da8d833829a36701655415951deb6540b11ba7c7e2a69e622d6920725685c817cda08419e70c7d0cbc9183a6c0c2f
data/README.md CHANGED
@@ -26,13 +26,9 @@ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announceme
26
26
 
27
27
  [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
28
28
 
29
- ### Current Release 2.7.1
29
+ ### Current Release 2.7.2
30
30
 
31
- - Fixed bug in new push_key which caused duplicate characters.
32
-
33
- ### Current Release 2.7.0
34
-
35
- - Added the push_key() method to the StringWriter and StreamWriter classes.
31
+ - Added option return nil if nil is provided as input to load.
36
32
 
37
33
  [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
38
34
 
@@ -110,6 +110,7 @@ static VALUE float_sym;
110
110
  static VALUE indent_sym;
111
111
  static VALUE json_sym;
112
112
  static VALUE mode_sym;
113
+ static VALUE nilnil_sym;
113
114
  static VALUE null_sym;
114
115
  static VALUE object_sym;
115
116
  static VALUE ruby_sym;
@@ -156,6 +157,7 @@ struct _Options oj_default_options = {
156
157
  Yes, // bigdec_as_num
157
158
  AutoDec, // bigdec_load
158
159
  No, // to_json
160
+ No, // nilnil
159
161
  json_class, // create_id
160
162
  10, // create_id_len
161
163
  9, // sec_prec
@@ -181,6 +183,7 @@ static VALUE define_mimic_json(int argc, VALUE *argv, VALUE self);
181
183
  * - create_id: [String|nil] create id for json compatible object encoding, default is 'json_create'
182
184
  * - second_precision: [Fixnum|nil] number of digits after the decimal when dumping the seconds portion of time
183
185
  * - use_to_json: [true|false|nil] call to_json() methods on dump, default is false
186
+ * - nilnil: [true|false|nil] if true a nil input to load will return nil and not raise an Exception
184
187
  * - allow_gc: [true|false|nil] allow or prohibit GC during parsing, default is true (allow)
185
188
  * @return [Hash] all current option settings.
186
189
  */
@@ -196,6 +199,7 @@ get_def_opts(VALUE self) {
196
199
  rb_hash_aset(opts, symbol_keys_sym, (Yes == oj_default_options.sym_key) ? Qtrue : ((No == oj_default_options.sym_key) ? Qfalse : Qnil));
197
200
  rb_hash_aset(opts, bigdecimal_as_decimal_sym, (Yes == oj_default_options.bigdec_as_num) ? Qtrue : ((No == oj_default_options.bigdec_as_num) ? Qfalse : Qnil));
198
201
  rb_hash_aset(opts, use_to_json_sym, (Yes == oj_default_options.to_json) ? Qtrue : ((No == oj_default_options.to_json) ? Qfalse : Qnil));
202
+ rb_hash_aset(opts, nilnil_sym, (Yes == oj_default_options.nilnil) ? Qtrue : ((No == oj_default_options.nilnil) ? Qfalse : Qnil));
199
203
  rb_hash_aset(opts, allow_gc_sym, (Yes == oj_default_options.allow_gc) ? Qtrue : ((No == oj_default_options.allow_gc) ? Qfalse : Qnil));
200
204
  switch (oj_default_options.mode) {
201
205
  case StrictMode: rb_hash_aset(opts, mode_sym, strict_sym); break;
@@ -256,6 +260,7 @@ get_def_opts(VALUE self) {
256
260
  * @param [String|nil] :create_id create id for json compatible object encoding
257
261
  * @param [Fixnum|nil] :second_precision number of digits after the decimal when dumping the seconds portion of time
258
262
  * @param [true|false|nil] :use_to_json call to_json() methods on dump, default is false
263
+ * @param [true|false|nil] :nilnil if true a nil input to load will return nil and not raise an Exception
259
264
  * @param [true|false|nil] :allow_gc allow or prohibit GC during parsing, default is true (allow)
260
265
  * @return [nil]
261
266
  */
@@ -268,6 +273,7 @@ set_def_opts(VALUE self, VALUE opts) {
268
273
  { class_cache_sym, &oj_default_options.class_cache },
269
274
  { bigdecimal_as_decimal_sym, &oj_default_options.bigdec_as_num },
270
275
  { use_to_json_sym, &oj_default_options.to_json },
276
+ { nilnil_sym, &oj_default_options.nilnil },
271
277
  { allow_gc_sym, &oj_default_options.allow_gc },
272
278
  { Qnil, 0 }
273
279
  };
@@ -399,6 +405,7 @@ oj_parse_options(VALUE ropts, Options copts) {
399
405
  { class_cache_sym, &copts->class_cache },
400
406
  { bigdecimal_as_decimal_sym, &copts->bigdec_as_num },
401
407
  { use_to_json_sym, &copts->to_json },
408
+ { nilnil_sym, &copts->nilnil },
402
409
  { allow_gc_sym, &copts->allow_gc },
403
410
  { Qnil, 0 }
404
411
  };
@@ -517,7 +524,7 @@ oj_parse_options(VALUE ropts, Options copts) {
517
524
  copts->escape_mode = JSONEsc;
518
525
  }
519
526
  }
520
- }
527
+ }
521
528
 
522
529
  /* Document-method: strict_load
523
530
  * call-seq: strict_load(json, options) => Hash, Array, String, Fixnum, Float, true, false, or nil
@@ -1698,6 +1705,7 @@ define_mimic_json(int argc, VALUE *argv, VALUE self) {
1698
1705
 
1699
1706
  oj_default_options.mode = CompatMode;
1700
1707
  oj_default_options.escape_mode = ASCIIEsc;
1708
+ oj_default_options.nilnil = Yes;
1701
1709
 
1702
1710
  return mimic;
1703
1711
  }
@@ -1852,6 +1860,7 @@ void Init_oj() {
1852
1860
  bigdecimal_load_sym = ID2SYM(rb_intern("bigdecimal_load"));rb_gc_register_address(&bigdecimal_load_sym);
1853
1861
  bigdecimal_sym = ID2SYM(rb_intern("bigdecimal")); rb_gc_register_address(&bigdecimal_sym);
1854
1862
  circular_sym = ID2SYM(rb_intern("circular")); rb_gc_register_address(&circular_sym);
1863
+ nilnil_sym = ID2SYM(rb_intern("nilnil")); rb_gc_register_address(&nilnil_sym);
1855
1864
  class_cache_sym = ID2SYM(rb_intern("class_cache")); rb_gc_register_address(&class_cache_sym);
1856
1865
  compat_sym = ID2SYM(rb_intern("compat")); rb_gc_register_address(&compat_sym);
1857
1866
  create_id_sym = ID2SYM(rb_intern("create_id")); rb_gc_register_address(&create_id_sym);
@@ -136,6 +136,7 @@ typedef struct _Options {
136
136
  char bigdec_as_num; // YesNo
137
137
  char bigdec_load; // BigLoad
138
138
  char to_json; // YesNo
139
+ char nilnil; // YesNo
139
140
  const char *create_id; // 0 or string
140
141
  size_t create_id_len; // length of create_id
141
142
  int sec_prec; // second precision when dumping time
@@ -742,6 +742,8 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len) {
742
742
  } else if (rb_type(input) == T_STRING) {
743
743
  pi->json = rb_string_value_cstr((VALUE*)&input);
744
744
  pi->end = pi->json + RSTRING_LEN(input);
745
+ } else if (Qnil == input && Yes == pi->options.nilnil) {
746
+ return Qnil;
745
747
  } else {
746
748
  VALUE clas = rb_obj_class(input);
747
749
  volatile VALUE s;
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.7.1'
4
+ VERSION = '2.7.2'
5
5
  end
@@ -135,6 +135,7 @@ class Juice < ::Test::Unit::TestCase
135
135
  :bigdecimal_as_decimal=>true,
136
136
  :bigdecimal_load=>:auto,
137
137
  :use_to_json=>false,
138
+ :nilnil=>false,
138
139
  :allow_gc=>true,
139
140
  :create_id=>'json_class'}, opts)
140
141
  end
@@ -153,6 +154,7 @@ class Juice < ::Test::Unit::TestCase
153
154
  :bigdecimal_as_decimal=>true,
154
155
  :bigdecimal_load=>:auto,
155
156
  :use_to_json=>true,
157
+ :nilnil=>false,
156
158
  :allow_gc=>true,
157
159
  :create_id=>'json_class'}
158
160
  o2 = {
@@ -168,6 +170,7 @@ class Juice < ::Test::Unit::TestCase
168
170
  :bigdecimal_as_decimal=>false,
169
171
  :bigdecimal_load=>:bigdecimal,
170
172
  :use_to_json=>false,
173
+ :nilnil=>true,
171
174
  :allow_gc=>false,
172
175
  :create_id=>nil}
173
176
  o3 = { :indent => 4 }
@@ -1106,6 +1109,21 @@ class Juice < ::Test::Unit::TestCase
1106
1109
  assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
1107
1110
  end
1108
1111
 
1112
+ def test_nilnil_false
1113
+ begin
1114
+ Oj.load(nil)
1115
+ rescue Exception => e
1116
+ assert(true)
1117
+ return
1118
+ end
1119
+ assert(false, "*** expected an exception")
1120
+ end
1121
+
1122
+ def test_nilnil_true
1123
+ obj = Oj.load(nil, :nilnil => true)
1124
+ assert_equal(nil, obj)
1125
+ end
1126
+
1109
1127
  # Rails re-call test. Active support recalls the json dumper when the to_json
1110
1128
  # method is called. This mimics that and verifies Oj detects it.
1111
1129
  def test_rails_like
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-30 00:00:00.000000000 Z
11
+ date: 2014-04-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'The fastest JSON parser and object serializer. '
14
14
  email: peter@ohler.com