oj 3.2.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/oj/custom.c +3 -1
- data/ext/oj/dump_compat.c +3 -3
- data/ext/oj/dump_strict.c +11 -3
- data/ext/oj/mimic_json.c +7 -3
- data/ext/oj/oj.c +6 -7
- data/lib/oj/version.rb +1 -1
- metadata +65 -67
- data/test/bug.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70265e88ab461a3fc0c6207db8f333504df2f53c
|
4
|
+
data.tar.gz: 9a0bd96af511e73ed8f5aa6caaebe2f7a4b00bed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 546692fc1cdc5bebc182b539a38267789ee67e354dd791154e6141df22ab0514927a0c501915bb1ed38c1b3ebc64c07986326abcb5980c9550a0fd68717bd854
|
7
|
+
data.tar.gz: dedc2c96f831f2d09576c74bf6d9ec97af06ca36497e389a02d321d8f60c3645aaeb81bcc3384835fad28d9638b02309473071e37281440760c7f7bc378dffc5
|
data/ext/oj/custom.c
CHANGED
@@ -564,6 +564,7 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
|
|
564
564
|
size_t size = 0;
|
565
565
|
int d2 = depth + 1;
|
566
566
|
int cnt;
|
567
|
+
bool class_written = false;
|
567
568
|
|
568
569
|
assure_size(out, 2);
|
569
570
|
*out->cur++ = '{';
|
@@ -592,9 +593,10 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
|
|
592
593
|
memcpy(out->cur, classname, len);
|
593
594
|
out->cur += len;
|
594
595
|
*out->cur++ = '"';
|
596
|
+
class_written = true;
|
595
597
|
}
|
596
598
|
cnt = (int)rb_ivar_count(obj);
|
597
|
-
if (
|
599
|
+
if (class_written) {
|
598
600
|
*out->cur++ = ',';
|
599
601
|
}
|
600
602
|
if (0 == cnt && Qundef == clas) {
|
data/ext/oj/dump_compat.c
CHANGED
@@ -593,19 +593,19 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
593
593
|
*b++ = '\0';
|
594
594
|
cnt = 3;
|
595
595
|
} else if (OJ_INFINITY == d) {
|
596
|
-
if (out->opts->dump_opts.nan_dump) {
|
596
|
+
if (WordNan == out->opts->dump_opts.nan_dump) {
|
597
597
|
strcpy(buf, "Infinity");
|
598
598
|
} else {
|
599
599
|
raise_json_err("Infinity not allowed in JSON.", "GeneratorError");
|
600
600
|
}
|
601
601
|
} else if (-OJ_INFINITY == d) {
|
602
|
-
if (out->opts->dump_opts.nan_dump) {
|
602
|
+
if (WordNan == out->opts->dump_opts.nan_dump) {
|
603
603
|
strcpy(buf, "-Infinity");
|
604
604
|
} else {
|
605
605
|
raise_json_err("-Infinity not allowed in JSON.", "GeneratorError");
|
606
606
|
}
|
607
607
|
} else if (isnan(d)) {
|
608
|
-
if (out->opts->dump_opts.nan_dump) {
|
608
|
+
if (WordNan == out->opts->dump_opts.nan_dump) {
|
609
609
|
strcpy(buf, "NaN");
|
610
610
|
} else {
|
611
611
|
raise_json_err("NaN not allowed in JSON.", "GeneratorError");
|
data/ext/oj/dump_strict.c
CHANGED
@@ -167,7 +167,11 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
167
167
|
} else {
|
168
168
|
fill_indent(out, d2);
|
169
169
|
}
|
170
|
-
|
170
|
+
if (NullMode == out->opts->mode) {
|
171
|
+
oj_dump_null_val(rb_ary_entry(a, i), d2, out);
|
172
|
+
} else {
|
173
|
+
oj_dump_strict_val(rb_ary_entry(a, i), d2, out);
|
174
|
+
}
|
171
175
|
if (i < cnt) {
|
172
176
|
*out->cur++ = ',';
|
173
177
|
}
|
@@ -203,7 +207,7 @@ hash_cb(VALUE key, VALUE value, Out out) {
|
|
203
207
|
int rtype = rb_type(key);
|
204
208
|
|
205
209
|
if (rtype != T_STRING && rtype != T_SYMBOL) {
|
206
|
-
rb_raise(rb_eTypeError, "In :strict mode all Hash keys must be Strings or Symbols, not %s.\n", rb_class2name(rb_obj_class(key)));
|
210
|
+
rb_raise(rb_eTypeError, "In :strict and :null mode all Hash keys must be Strings or Symbols, not %s.\n", rb_class2name(rb_obj_class(key)));
|
207
211
|
}
|
208
212
|
if (out->omit_nil && Qnil == value) {
|
209
213
|
return ST_CONTINUE;
|
@@ -249,7 +253,11 @@ hash_cb(VALUE key, VALUE value, Out out) {
|
|
249
253
|
out->cur += out->opts->dump_opts.after_size;
|
250
254
|
}
|
251
255
|
}
|
252
|
-
|
256
|
+
if (NullMode == out->opts->mode) {
|
257
|
+
oj_dump_null_val(value, depth, out);
|
258
|
+
} else {
|
259
|
+
oj_dump_strict_val(value, depth, out);
|
260
|
+
}
|
253
261
|
out->depth = depth;
|
254
262
|
*out->cur++ = ',';
|
255
263
|
|
data/ext/oj/mimic_json.c
CHANGED
@@ -108,7 +108,11 @@ oj_parse_mimic_dump_options(VALUE ropts, Options copts) {
|
|
108
108
|
}
|
109
109
|
}
|
110
110
|
if (Qnil != (v = rb_hash_lookup(ropts, oj_allow_nan_sym))) {
|
111
|
-
|
111
|
+
if (Qtrue == v) {
|
112
|
+
copts->dump_opts.nan_dump = WordNan;
|
113
|
+
} else {
|
114
|
+
copts->dump_opts.nan_dump = RaiseNan;
|
115
|
+
}
|
112
116
|
}
|
113
117
|
if (Qnil != (v = rb_hash_lookup(ropts, oj_indent_sym))) {
|
114
118
|
rb_check_type(v, T_STRING);
|
@@ -362,7 +366,7 @@ mimic_generate_core(int argc, VALUE *argv, Options copts) {
|
|
362
366
|
out.caller = CALLER_GENERATE;
|
363
367
|
// For obj.to_json or generate nan is not allowed but if called from dump
|
364
368
|
// it is.
|
365
|
-
copts->dump_opts.nan_dump =
|
369
|
+
copts->dump_opts.nan_dump = RaiseNan;
|
366
370
|
copts->mode = CompatMode;
|
367
371
|
if (2 == argc && Qnil != argv[1]) {
|
368
372
|
oj_parse_mimic_dump_options(argv[1], copts);
|
@@ -698,7 +702,7 @@ static struct _Options mimic_object_to_json_options = {
|
|
698
702
|
0, // after_size
|
699
703
|
0, // hash_size
|
700
704
|
0, // array_size
|
701
|
-
|
705
|
+
RaiseNan,// nan_dump
|
702
706
|
false, // omit_nil
|
703
707
|
100, // max_depth
|
704
708
|
},
|
data/ext/oj/oj.c
CHANGED
@@ -222,7 +222,7 @@ struct _Options oj_default_options = {
|
|
222
222
|
* - *:time_format* [_:unix_|_:unix_zone_|_:xmlschema_|_:ruby_] time format when dumping in :compat and :object mode
|
223
223
|
* - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or as a String
|
224
224
|
* - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_] load decimals as BigDecimal instead of as a Float. :auto pick the most precise for the number of digits.
|
225
|
-
* - *:create_id* [_String_|_nil_] create id for json compatible object encoding, default is '
|
225
|
+
* - *:create_id* [_String_|_nil_] create id for json compatible object encoding, default is 'json_class'
|
226
226
|
* - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the seconds portion of time
|
227
227
|
* - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0 indicates use Ruby
|
228
228
|
* - *:use_to_json* [_Boolean_|_nil_] call to_json() methods on dump, default is false
|
@@ -949,12 +949,12 @@ dump(int argc, VALUE *argv, VALUE self) {
|
|
949
949
|
if (1 > argc) {
|
950
950
|
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1).");
|
951
951
|
}
|
952
|
+
if (CompatMode == copts.mode) {
|
953
|
+
copts.dump_opts.nan_dump = WordNan;
|
954
|
+
}
|
952
955
|
if (2 == argc) {
|
953
956
|
oj_parse_options(argv[1], &copts);
|
954
957
|
}
|
955
|
-
if (CompatMode == copts.mode) {
|
956
|
-
copts.dump_opts.nan_dump = true;
|
957
|
-
}
|
958
958
|
out.buf = buf;
|
959
959
|
out.end = buf + sizeof(buf) - 10;
|
960
960
|
out.allocated = false;
|
@@ -1001,7 +1001,7 @@ to_json(int argc, VALUE *argv, VALUE self) {
|
|
1001
1001
|
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1).");
|
1002
1002
|
}
|
1003
1003
|
copts.escape_mode = JXEsc;
|
1004
|
-
copts.dump_opts.nan_dump =
|
1004
|
+
copts.dump_opts.nan_dump = RaiseNan;
|
1005
1005
|
if (2 == argc) {
|
1006
1006
|
oj_parse_mimic_dump_options(argv[1], &copts);
|
1007
1007
|
}
|
@@ -1013,8 +1013,7 @@ to_json(int argc, VALUE *argv, VALUE self) {
|
|
1013
1013
|
out.omit_nil = copts.dump_opts.omit_nil;
|
1014
1014
|
// For obj.to_json or generate nan is not allowed but if called from dump
|
1015
1015
|
// it is.
|
1016
|
-
copts
|
1017
|
-
oj_dump_obj_to_json_using_params(*argv, &copts, &out, argc - 1,argv + 1);
|
1016
|
+
oj_dump_obj_to_json_using_params(*argv, &copts, &out, argc - 1, argv + 1);
|
1018
1017
|
|
1019
1018
|
if (0 == out.buf) {
|
1020
1019
|
rb_raise(rb_eNoMemError, "Not enough memory.");
|
data/lib/oj/version.rb
CHANGED
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: 3.2.
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -60,14 +60,14 @@ extensions:
|
|
60
60
|
extra_rdoc_files:
|
61
61
|
- README.md
|
62
62
|
- pages/Advanced.md
|
63
|
-
- pages/Compatibility.md
|
64
|
-
- pages/Custom.md
|
65
63
|
- pages/Encoding.md
|
66
|
-
- pages/JsonGem.md
|
67
64
|
- pages/Modes.md
|
68
|
-
- pages/Options.md
|
69
|
-
- pages/Rails.md
|
70
65
|
- pages/Security.md
|
66
|
+
- pages/JsonGem.md
|
67
|
+
- pages/Rails.md
|
68
|
+
- pages/Compatibility.md
|
69
|
+
- pages/Custom.md
|
70
|
+
- pages/Options.md
|
71
71
|
files:
|
72
72
|
- LICENSE
|
73
73
|
- README.md
|
@@ -149,7 +149,6 @@ files:
|
|
149
149
|
- test/activesupport5/encoding_test_cases.rb
|
150
150
|
- test/activesupport5/test_helper.rb
|
151
151
|
- test/activesupport5/time_zone_test_helpers.rb
|
152
|
-
- test/bug.rb
|
153
152
|
- test/files.rb
|
154
153
|
- test/helper.rb
|
155
154
|
- test/isolated/shared.rb
|
@@ -240,76 +239,75 @@ signing_key:
|
|
240
239
|
specification_version: 4
|
241
240
|
summary: A fast JSON parser and serializer.
|
242
241
|
test_files:
|
243
|
-
- test/_test_active.rb
|
244
|
-
- test/_test_active_mimic.rb
|
245
|
-
- test/_test_mimic_rails.rb
|
246
|
-
- test/activesupport4/decoding_test.rb
|
247
|
-
- test/activesupport4/encoding_test.rb
|
248
|
-
- test/activesupport4/test_helper.rb
|
249
|
-
- test/activesupport5/decoding_test.rb
|
250
|
-
- test/activesupport5/encoding_test.rb
|
251
|
-
- test/activesupport5/encoding_test_cases.rb
|
252
242
|
- test/activesupport5/test_helper.rb
|
253
243
|
- test/activesupport5/time_zone_test_helpers.rb
|
254
|
-
- test/
|
244
|
+
- test/activesupport5/decoding_test.rb
|
245
|
+
- test/activesupport5/encoding_test_cases.rb
|
246
|
+
- test/activesupport5/encoding_test.rb
|
247
|
+
- test/test_file.rb
|
255
248
|
- test/files.rb
|
256
|
-
- test/helper.rb
|
257
|
-
- test/isolated/shared.rb
|
258
|
-
- test/isolated/test_mimic_after.rb
|
259
|
-
- test/isolated/test_mimic_alone.rb
|
260
|
-
- test/isolated/test_mimic_as_json.rb
|
261
|
-
- test/isolated/test_mimic_before.rb
|
262
|
-
- test/isolated/test_mimic_define.rb
|
263
|
-
- test/isolated/test_mimic_rails_after.rb
|
264
|
-
- test/isolated/test_mimic_rails_before.rb
|
265
|
-
- test/isolated/test_mimic_redefine.rb
|
266
|
-
- test/json_gem/json_addition_test.rb
|
267
|
-
- test/json_gem/json_common_interface_test.rb
|
268
|
-
- test/json_gem/json_encoding_test.rb
|
269
|
-
- test/json_gem/json_ext_parser_test.rb
|
270
|
-
- test/json_gem/json_fixtures_test.rb
|
271
|
-
- test/json_gem/json_generator_test.rb
|
272
|
-
- test/json_gem/json_generic_object_test.rb
|
273
|
-
- test/json_gem/json_parser_test.rb
|
274
|
-
- test/json_gem/json_string_matching_test.rb
|
275
|
-
- test/json_gem/test_helper.rb
|
276
|
-
- test/perf.rb
|
277
|
-
- test/perf_compat.rb
|
278
|
-
- test/perf_fast.rb
|
279
|
-
- test/perf_file.rb
|
280
|
-
- test/perf_object.rb
|
281
|
-
- test/perf_saj.rb
|
282
249
|
- test/perf_scp.rb
|
283
|
-
- test/
|
284
|
-
- test/
|
285
|
-
- test/
|
286
|
-
- test/
|
287
|
-
- test/
|
250
|
+
- test/test_debian.rb
|
251
|
+
- test/test_gc.rb
|
252
|
+
- test/_test_mimic_rails.rb
|
253
|
+
- test/test_writer.rb
|
254
|
+
- test/test_hash.rb
|
288
255
|
- test/sample/file.rb
|
289
|
-
- test/sample/group.rb
|
290
256
|
- test/sample/hasprops.rb
|
291
257
|
- test/sample/layer.rb
|
292
|
-
- test/sample/
|
258
|
+
- test/sample/change.rb
|
259
|
+
- test/sample/doc.rb
|
293
260
|
- test/sample/oval.rb
|
294
|
-
- test/sample/rect.rb
|
295
261
|
- test/sample/shape.rb
|
296
262
|
- test/sample/text.rb
|
297
|
-
- test/sample.rb
|
298
|
-
- test/
|
299
|
-
- test/
|
300
|
-
- test/
|
301
|
-
- test/
|
302
|
-
- test/test_fast.rb
|
303
|
-
- test/test_file.rb
|
304
|
-
- test/test_gc.rb
|
305
|
-
- test/test_hash.rb
|
306
|
-
- test/test_null.rb
|
263
|
+
- test/sample/group.rb
|
264
|
+
- test/sample/dir.rb
|
265
|
+
- test/sample/line.rb
|
266
|
+
- test/sample/rect.rb
|
267
|
+
- test/tests.rb
|
307
268
|
- test/test_object.rb
|
269
|
+
- test/tests_mimic.rb
|
270
|
+
- test/perf_saj.rb
|
271
|
+
- test/tests_mimic_addition.rb
|
308
272
|
- test/test_saj.rb
|
273
|
+
- test/sample.rb
|
309
274
|
- test/test_scp.rb
|
310
|
-
- test/
|
275
|
+
- test/perf_object.rb
|
276
|
+
- test/perf_simple.rb
|
277
|
+
- test/test_null.rb
|
278
|
+
- test/_test_active_mimic.rb
|
279
|
+
- test/_test_active.rb
|
280
|
+
- test/test_compat.rb
|
281
|
+
- test/sample_json.rb
|
282
|
+
- test/json_gem/test_helper.rb
|
283
|
+
- test/json_gem/json_generic_object_test.rb
|
284
|
+
- test/json_gem/json_common_interface_test.rb
|
285
|
+
- test/json_gem/json_string_matching_test.rb
|
286
|
+
- test/json_gem/json_addition_test.rb
|
287
|
+
- test/json_gem/json_fixtures_test.rb
|
288
|
+
- test/json_gem/json_generator_test.rb
|
289
|
+
- test/json_gem/json_ext_parser_test.rb
|
290
|
+
- test/json_gem/json_parser_test.rb
|
291
|
+
- test/json_gem/json_encoding_test.rb
|
292
|
+
- test/helper.rb
|
293
|
+
- test/activesupport4/test_helper.rb
|
294
|
+
- test/activesupport4/decoding_test.rb
|
295
|
+
- test/activesupport4/encoding_test.rb
|
296
|
+
- test/perf_file.rb
|
297
|
+
- test/perf_compat.rb
|
311
298
|
- test/test_various.rb
|
312
|
-
- test/
|
313
|
-
- test/
|
314
|
-
- test/
|
315
|
-
- test/
|
299
|
+
- test/test_strict.rb
|
300
|
+
- test/test_custom.rb
|
301
|
+
- test/perf_strict.rb
|
302
|
+
- test/perf_fast.rb
|
303
|
+
- test/isolated/test_mimic_alone.rb
|
304
|
+
- test/isolated/test_mimic_after.rb
|
305
|
+
- test/isolated/test_mimic_as_json.rb
|
306
|
+
- test/isolated/test_mimic_rails_after.rb
|
307
|
+
- test/isolated/test_mimic_before.rb
|
308
|
+
- test/isolated/test_mimic_rails_before.rb
|
309
|
+
- test/isolated/test_mimic_define.rb
|
310
|
+
- test/isolated/shared.rb
|
311
|
+
- test/isolated/test_mimic_redefine.rb
|
312
|
+
- test/perf.rb
|
313
|
+
- test/test_fast.rb
|
data/test/bug.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
%w(lib ext test).each do |dir|
|
5
|
-
$LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'rails'
|
9
|
-
require 'active_support/json'
|
10
|
-
require 'oj'
|
11
|
-
|
12
|
-
Oj.optimize_rails
|
13
|
-
|
14
|
-
puts JSON.parse('{"a":1}', symbolize_names: true)
|
15
|
-
|
16
|
-
|