oj 3.10.14 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/ext/oj/buf.h +2 -30
  3. data/ext/oj/cache8.h +1 -29
  4. data/ext/oj/circarray.c +4 -8
  5. data/ext/oj/circarray.h +1 -4
  6. data/ext/oj/code.c +3 -6
  7. data/ext/oj/code.h +1 -4
  8. data/ext/oj/compat.c +1 -4
  9. data/ext/oj/custom.c +1 -4
  10. data/ext/oj/dump.c +23 -13
  11. data/ext/oj/dump.h +1 -4
  12. data/ext/oj/dump_compat.c +1 -4
  13. data/ext/oj/dump_leaf.c +2 -5
  14. data/ext/oj/dump_object.c +1 -4
  15. data/ext/oj/dump_strict.c +1 -4
  16. data/ext/oj/encode.h +1 -29
  17. data/ext/oj/err.c +1 -4
  18. data/ext/oj/err.h +1 -29
  19. data/ext/oj/fast.c +14 -42
  20. data/ext/oj/hash.c +4 -32
  21. data/ext/oj/hash.h +1 -29
  22. data/ext/oj/hash_test.c +1 -29
  23. data/ext/oj/mimic_json.c +5 -6
  24. data/ext/oj/object.c +1 -4
  25. data/ext/oj/odd.c +1 -4
  26. data/ext/oj/odd.h +1 -4
  27. data/ext/oj/oj.c +24 -4
  28. data/ext/oj/oj.h +3 -4
  29. data/ext/oj/parse.c +19 -19
  30. data/ext/oj/parse.h +1 -4
  31. data/ext/oj/rails.c +1 -4
  32. data/ext/oj/rails.h +1 -4
  33. data/ext/oj/reader.c +5 -8
  34. data/ext/oj/reader.h +2 -5
  35. data/ext/oj/resolve.c +1 -4
  36. data/ext/oj/resolve.h +1 -4
  37. data/ext/oj/rxclass.c +3 -6
  38. data/ext/oj/rxclass.h +1 -4
  39. data/ext/oj/saj.c +6 -9
  40. data/ext/oj/scp.c +1 -4
  41. data/ext/oj/sparse.c +40 -23
  42. data/ext/oj/stream_writer.c +4 -9
  43. data/ext/oj/strict.c +3 -6
  44. data/ext/oj/string_writer.c +1 -4
  45. data/ext/oj/trace.c +5 -8
  46. data/ext/oj/trace.h +1 -4
  47. data/ext/oj/util.c +1 -1
  48. data/ext/oj/util.h +1 -1
  49. data/ext/oj/val_stack.c +1 -29
  50. data/ext/oj/val_stack.h +1 -29
  51. data/ext/oj/wab.c +1 -4
  52. data/lib/oj/mimic.rb +45 -1
  53. data/lib/oj/version.rb +1 -1
  54. data/pages/Modes.md +1 -0
  55. data/pages/Options.md +12 -0
  56. data/test/test_compat.rb +14 -1
  57. data/test/test_rails.rb +9 -0
  58. data/test/test_various.rb +1 -0
  59. metadata +85 -85
@@ -1,7 +1,4 @@
1
- /* wab.c
2
- * Copyright (c) 2012, Peter Ohler
3
- * All rights reserved.
4
- */
1
+ // Copyright (c) 2012 Peter Ohler. All rights reserved.
5
2
 
6
3
  #include <stdlib.h>
7
4
  #include <stdio.h>
@@ -8,6 +8,50 @@ end
8
8
 
9
9
  module Oj
10
10
 
11
+ ##
12
+ # Custom mode can be used to emulate the compat mode with some minor
13
+ # differences. These are the options that setup the custom mode to be like
14
+ # the compat mode.
15
+ CUSTOM_MIMIC_JSON_OPTIONS = {
16
+ allow_gc: true,
17
+ allow_invalid_unicode: false,
18
+ allow_nan: false,
19
+ array_class: nil,
20
+ array_nl: nil,
21
+ auto_define: false,
22
+ bigdecimal_as_decimal: false,
23
+ bigdecimal_load: :auto,
24
+ circular: false,
25
+ class_cache: false,
26
+ create_additions: false,
27
+ create_id: "json_class",
28
+ empty_string: false,
29
+ escape_mode: :unicode_xss,
30
+ float_precision: 0,
31
+ hash_class: nil,
32
+ ignore: nil,
33
+ ignore_under: false,
34
+ indent: 0,
35
+ integer_range: nil,
36
+ mode: :custom,
37
+ nan: :raise,
38
+ nilnil: false,
39
+ object_nl: nil,
40
+ omit_nil: false,
41
+ quirks_mode: true,
42
+ safe: false,
43
+ second_precision: 3,
44
+ space: nil,
45
+ space_before: nil,
46
+ symbol_keys: false,
47
+ time_format: :ruby,
48
+ trace: false,
49
+ use_as_json: false,
50
+ use_raw_json: false,
51
+ use_to_hash: false,
52
+ use_to_json: true,
53
+ }
54
+
11
55
  # A bit hack-ish but does the trick. The JSON.dump_default_options is a Hash
12
56
  # but in mimic we use a C struct to store defaults. This class creates a view
13
57
  # onto that struct.
@@ -38,7 +82,7 @@ module Oj
38
82
 
39
83
  jfile = File.join(d, 'json.rb')
40
84
  $LOADED_FEATURES << jfile unless $LOADED_FEATURES.include?(jfile) if File.exist?(jfile)
41
-
85
+
42
86
  Dir.glob(File.join(d, 'json', '**', '*.rb')).each do |file|
43
87
  # allow json/add/xxx to be loaded. User can override with Oj.add_to_json(xxx).
44
88
  $LOADED_FEATURES << file unless $LOADED_FEATURES.include?(file) unless file.include?('add')
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.10.14'
4
+ VERSION = '3.11.0'
5
5
  end
@@ -96,6 +96,7 @@ information.
96
96
  | :auto_define | Boolean | | | | | x | x | |
97
97
  | :bigdecimal_as_decimal | Boolean | | | | 3 | x | x | |
98
98
  | :bigdecimal_load | Boolean | | | | | | x | |
99
+ | :compat_bigdecimal | Boolean | | | x | | | x | |
99
100
  | :circular | Boolean | x | x | x | x | x | x | |
100
101
  | :class_cache | Boolean | | | | | x | x | |
101
102
  | :create_additions | Boolean | | | x | x | | x | |
@@ -66,6 +66,18 @@ Determines how to load decimals.
66
66
 
67
67
  - `:auto` the most precise for the number of digits is used.
68
68
 
69
+ This can also be set with `:decimal_class` when used as a load or
70
+ parse option to match the JSON gem. In that case either `Float`,
71
+ `BigDecimal`, or `nil` can be provided.
72
+
73
+ ### :compat_bigdecimal [Boolean]
74
+
75
+ Determines how to load decimals when in `:compat` mode.
76
+
77
+ - `true` convert all decimal numbers to BigDecimal.
78
+
79
+ - `false` convert all decimal numbers to Float.
80
+
69
81
  ### :circular [Boolean]
70
82
 
71
83
  Detect circular references while dumping. In :compat mode raise a
@@ -236,6 +236,12 @@ class CompatJuice < Minitest::Test
236
236
  assert_equal({"a\nb" => true, "c\td" => false}, obj)
237
237
  end
238
238
 
239
+ def test_invalid_escapes_handled
240
+ json = '{"subtext":"\"404er\” \w \k \3 \a"}'
241
+ obj = Oj.compat_load(json)
242
+ assert_equal({"subtext" => "\"404er” w k 3 a"}, obj)
243
+ end
244
+
239
245
  def test_hash_escaping
240
246
  json = Oj.to_json({'<>' => '<>'}, mode: :compat)
241
247
  assert_equal(json, '{"<>":"<>"}')
@@ -271,12 +277,19 @@ class CompatJuice < Minitest::Test
271
277
  # BigDecimal
272
278
  def test_bigdecimal
273
279
  # BigDecimals are dumped as strings and can not be restored to the
274
- # original value.
280
+ # original value without using an undocumented feature of the JSON gem.
275
281
  json = Oj.dump(BigDecimal('3.14159265358979323846'))
276
282
  # 2.4.0 changes the exponent to lowercase
277
283
  assert_equal('"0.314159265358979323846e1"', json.downcase)
278
284
  end
279
285
 
286
+ def test_decimal_class
287
+ big = BigDecimal('3.14159265358979323846')
288
+ # :decimal_class is the undocumented feature.
289
+ json = Oj.load('3.14159265358979323846', mode: :compat, decimal_class: BigDecimal)
290
+ assert_equal(big, json)
291
+ end
292
+
280
293
  def test_infinity
281
294
  assert_raises(Oj::ParseError) { Oj.load('Infinity', :mode => :strict) }
282
295
  x = Oj.load('Infinity', :mode => :compat)
@@ -23,4 +23,13 @@ class RailsJuice < Minitest::Test
23
23
  assert_equal('0.123e3', json.downcase)
24
24
  end
25
25
 
26
+ def test_invalid_encoding
27
+ assert_raises(EncodingError) {
28
+ Oj.dump("\"\xf3j", mode: :rails)
29
+ }
30
+ assert_raises(EncodingError) {
31
+ Oj.dump("\xf3j", mode: :rails)
32
+ }
33
+ end
34
+
26
35
  end
@@ -120,6 +120,7 @@ class Juice < Minitest::Test
120
120
  escape_mode: :ascii,
121
121
  time_format: :unix_zone,
122
122
  bigdecimal_load: :float,
123
+ compat_bigdecimal: true,
123
124
  create_id: 'classy',
124
125
  create_additions: true,
125
126
  space: 'z',
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.10.14
4
+ version: 3.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-05 00:00:00.000000000 Z
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -79,16 +79,16 @@ extensions:
79
79
  - ext/oj/extconf.rb
80
80
  extra_rdoc_files:
81
81
  - README.md
82
- - pages/Rails.md
83
- - pages/JsonGem.md
84
- - pages/Encoding.md
85
- - pages/WAB.md
86
- - pages/Custom.md
87
82
  - pages/Advanced.md
88
- - pages/Options.md
89
83
  - pages/Compatibility.md
84
+ - pages/Custom.md
85
+ - pages/Encoding.md
86
+ - pages/JsonGem.md
90
87
  - pages/Modes.md
88
+ - pages/Options.md
89
+ - pages/Rails.md
91
90
  - pages/Security.md
91
+ - pages/WAB.md
92
92
  files:
93
93
  - LICENSE
94
94
  - README.md
@@ -265,7 +265,7 @@ metadata:
265
265
  homepage_uri: http://www.ohler.com/oj/
266
266
  source_code_uri: https://github.com/ohler55/oj
267
267
  wiki_uri: https://github.com/ohler55/oj/wiki
268
- post_install_message:
268
+ post_install_message:
269
269
  rdoc_options:
270
270
  - "--title"
271
271
  - Oj
@@ -284,98 +284,98 @@ required_rubygems_version: !ruby/object:Gem::Requirement
284
284
  - !ruby/object:Gem::Version
285
285
  version: '0'
286
286
  requirements: []
287
- rubygems_version: 3.1.2
288
- signing_key:
287
+ rubygems_version: 3.2.3
288
+ signing_key:
289
289
  specification_version: 4
290
290
  summary: A fast JSON parser and serializer.
291
291
  test_files:
292
+ - test/_test_active.rb
293
+ - test/_test_active_mimic.rb
294
+ - test/_test_mimic_rails.rb
295
+ - test/activerecord/result_test.rb
296
+ - test/activesupport4/decoding_test.rb
297
+ - test/activesupport4/encoding_test.rb
298
+ - test/activesupport4/test_helper.rb
299
+ - test/activesupport5/abstract_unit.rb
300
+ - test/activesupport5/decoding_test.rb
301
+ - test/activesupport5/encoding_test.rb
302
+ - test/activesupport5/encoding_test_cases.rb
303
+ - test/activesupport5/test_helper.rb
304
+ - test/activesupport5/time_zone_test_helpers.rb
305
+ - test/activesupport6/abstract_unit.rb
306
+ - test/activesupport6/decoding_test.rb
307
+ - test/activesupport6/encoding_test.rb
308
+ - test/activesupport6/encoding_test_cases.rb
309
+ - test/activesupport6/test_common.rb
310
+ - test/activesupport6/test_helper.rb
311
+ - test/activesupport6/time_zone_test_helpers.rb
312
+ - test/bar.rb
313
+ - test/baz.rb
314
+ - test/files.rb
292
315
  - test/foo.rb
293
- - test/prec.rb
294
- - test/test_integer_range.rb
295
- - test/test_strict.rb
296
- - test/perf_strict.rb
297
- - test/tests.rb
298
- - test/perf_saj.rb
299
- - test/test_compat.rb
300
316
  - test/helper.rb
301
- - test/perf_file.rb
302
- - test/test_scp.rb
303
- - test/perf_compat.rb
304
- - test/json_gem/json_common_interface_test.rb
317
+ - test/isolated/shared.rb
318
+ - test/isolated/test_mimic_after.rb
319
+ - test/isolated/test_mimic_alone.rb
320
+ - test/isolated/test_mimic_as_json.rb
321
+ - test/isolated/test_mimic_before.rb
322
+ - test/isolated/test_mimic_define.rb
323
+ - test/isolated/test_mimic_rails_after.rb
324
+ - test/isolated/test_mimic_rails_before.rb
325
+ - test/isolated/test_mimic_redefine.rb
305
326
  - test/json_gem/json_addition_test.rb
306
- - test/json_gem/json_fixtures_test.rb
327
+ - test/json_gem/json_common_interface_test.rb
328
+ - test/json_gem/json_encoding_test.rb
307
329
  - test/json_gem/json_ext_parser_test.rb
308
- - test/json_gem/json_string_matching_test.rb
309
- - test/json_gem/json_generic_object_test.rb
330
+ - test/json_gem/json_fixtures_test.rb
310
331
  - test/json_gem/json_generator_test.rb
311
- - test/json_gem/test_helper.rb
312
- - test/json_gem/json_encoding_test.rb
332
+ - test/json_gem/json_generic_object_test.rb
313
333
  - test/json_gem/json_parser_test.rb
314
- - test/perf_wab.rb
315
- - test/test_file.rb
316
- - test/test_object.rb
317
- - test/sample.rb
334
+ - test/json_gem/json_string_matching_test.rb
335
+ - test/json_gem/test_helper.rb
336
+ - test/perf.rb
337
+ - test/perf_compat.rb
338
+ - test/perf_fast.rb
339
+ - test/perf_file.rb
318
340
  - test/perf_object.rb
319
- - test/test_hash.rb
320
- - test/test_custom.rb
321
- - test/bar.rb
322
- - test/activesupport4/encoding_test.rb
323
- - test/activesupport4/test_helper.rb
324
- - test/activesupport4/decoding_test.rb
325
- - test/sample_json.rb
326
- - test/activesupport5/encoding_test_cases.rb
327
- - test/activesupport5/encoding_test.rb
328
- - test/activesupport5/abstract_unit.rb
329
- - test/activesupport5/time_zone_test_helpers.rb
330
- - test/activesupport5/test_helper.rb
331
- - test/activesupport5/decoding_test.rb
332
- - test/test_saj.rb
341
+ - test/perf_saj.rb
333
342
  - test/perf_scp.rb
334
- - test/test_wab.rb
335
- - test/test_null.rb
336
- - test/_test_active.rb
337
- - test/_test_mimic_rails.rb
338
- - test/test_fast.rb
339
- - test/perf_fast.rb
343
+ - test/perf_simple.rb
344
+ - test/perf_strict.rb
345
+ - test/perf_wab.rb
346
+ - test/prec.rb
340
347
  - test/sample/change.rb
341
- - test/sample/text.rb
348
+ - test/sample/dir.rb
342
349
  - test/sample/doc.rb
343
- - test/sample/shape.rb
344
- - test/sample/layer.rb
345
- - test/sample/group.rb
346
350
  - test/sample/file.rb
347
- - test/sample/rect.rb
351
+ - test/sample/group.rb
348
352
  - test/sample/hasprops.rb
353
+ - test/sample/layer.rb
349
354
  - test/sample/line.rb
350
- - test/sample/dir.rb
351
355
  - test/sample/oval.rb
352
- - test/tests_mimic.rb
353
- - test/perf_simple.rb
354
- - test/zoo.rb
355
- - test/activerecord/result_test.rb
356
- - test/_test_active_mimic.rb
357
- - test/baz.rb
358
- - test/tests_mimic_addition.rb
359
- - test/test_writer.rb
360
- - test/test_rails.rb
361
- - test/perf.rb
362
- - test/isolated/test_mimic_define.rb
363
- - test/isolated/test_mimic_after.rb
364
- - test/isolated/test_mimic_rails_after.rb
365
- - test/isolated/test_mimic_before.rb
366
- - test/isolated/test_mimic_rails_before.rb
367
- - test/isolated/test_mimic_redefine.rb
368
- - test/isolated/shared.rb
369
- - test/isolated/test_mimic_alone.rb
370
- - test/isolated/test_mimic_as_json.rb
356
+ - test/sample/rect.rb
357
+ - test/sample/shape.rb
358
+ - test/sample/text.rb
359
+ - test/sample.rb
360
+ - test/sample_json.rb
361
+ - test/test_compat.rb
362
+ - test/test_custom.rb
371
363
  - test/test_debian.rb
364
+ - test/test_fast.rb
365
+ - test/test_file.rb
372
366
  - test/test_gc.rb
373
- - test/files.rb
367
+ - test/test_hash.rb
368
+ - test/test_integer_range.rb
369
+ - test/test_null.rb
370
+ - test/test_object.rb
371
+ - test/test_rails.rb
372
+ - test/test_saj.rb
373
+ - test/test_scp.rb
374
+ - test/test_strict.rb
374
375
  - test/test_various.rb
375
- - test/activesupport6/encoding_test_cases.rb
376
- - test/activesupport6/encoding_test.rb
377
- - test/activesupport6/abstract_unit.rb
378
- - test/activesupport6/time_zone_test_helpers.rb
379
- - test/activesupport6/test_helper.rb
380
- - test/activesupport6/test_common.rb
381
- - test/activesupport6/decoding_test.rb
376
+ - test/test_wab.rb
377
+ - test/test_writer.rb
378
+ - test/tests.rb
379
+ - test/tests_mimic.rb
380
+ - test/tests_mimic_addition.rb
381
+ - test/zoo.rb