oj 3.13.23 → 3.16.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +86 -0
  3. data/README.md +2 -2
  4. data/ext/oj/buf.h +7 -6
  5. data/ext/oj/cache.c +29 -26
  6. data/ext/oj/cache.h +3 -2
  7. data/ext/oj/cache8.c +10 -9
  8. data/ext/oj/circarray.c +7 -5
  9. data/ext/oj/circarray.h +2 -2
  10. data/ext/oj/code.c +5 -12
  11. data/ext/oj/code.h +2 -2
  12. data/ext/oj/compat.c +20 -60
  13. data/ext/oj/custom.c +26 -59
  14. data/ext/oj/debug.c +3 -9
  15. data/ext/oj/dump.c +103 -53
  16. data/ext/oj/dump.h +1 -4
  17. data/ext/oj/dump_compat.c +557 -592
  18. data/ext/oj/dump_leaf.c +3 -5
  19. data/ext/oj/dump_object.c +42 -48
  20. data/ext/oj/dump_strict.c +10 -22
  21. data/ext/oj/encoder.c +1 -1
  22. data/ext/oj/err.c +2 -13
  23. data/ext/oj/err.h +9 -12
  24. data/ext/oj/extconf.rb +16 -7
  25. data/ext/oj/fast.c +63 -98
  26. data/ext/oj/intern.c +62 -47
  27. data/ext/oj/intern.h +3 -7
  28. data/ext/oj/mem.c +318 -0
  29. data/ext/oj/mem.h +53 -0
  30. data/ext/oj/mimic_json.c +54 -38
  31. data/ext/oj/object.c +33 -43
  32. data/ext/oj/odd.c +8 -6
  33. data/ext/oj/odd.h +4 -4
  34. data/ext/oj/oj.c +245 -216
  35. data/ext/oj/oj.h +83 -81
  36. data/ext/oj/parse.c +109 -153
  37. data/ext/oj/parse.h +21 -24
  38. data/ext/oj/parser.c +80 -67
  39. data/ext/oj/parser.h +9 -8
  40. data/ext/oj/rails.c +71 -94
  41. data/ext/oj/reader.c +9 -14
  42. data/ext/oj/reader.h +4 -2
  43. data/ext/oj/resolve.c +3 -4
  44. data/ext/oj/rxclass.c +6 -5
  45. data/ext/oj/rxclass.h +1 -1
  46. data/ext/oj/saj.c +13 -15
  47. data/ext/oj/saj2.c +37 -49
  48. data/ext/oj/saj2.h +1 -1
  49. data/ext/oj/scp.c +6 -20
  50. data/ext/oj/sparse.c +22 -70
  51. data/ext/oj/stream_writer.c +46 -48
  52. data/ext/oj/strict.c +22 -56
  53. data/ext/oj/string_writer.c +64 -40
  54. data/ext/oj/trace.h +31 -4
  55. data/ext/oj/usual.c +125 -114
  56. data/ext/oj/usual.h +7 -6
  57. data/ext/oj/util.h +1 -1
  58. data/ext/oj/val_stack.c +13 -2
  59. data/ext/oj/val_stack.h +8 -7
  60. data/ext/oj/wab.c +25 -57
  61. data/lib/oj/active_support_helper.rb +1 -3
  62. data/lib/oj/bag.rb +7 -1
  63. data/lib/oj/easy_hash.rb +4 -5
  64. data/lib/oj/error.rb +0 -1
  65. data/lib/oj/json.rb +162 -150
  66. data/lib/oj/mimic.rb +7 -7
  67. data/lib/oj/schandler.rb +5 -4
  68. data/lib/oj/state.rb +8 -5
  69. data/lib/oj/version.rb +1 -2
  70. data/lib/oj.rb +2 -0
  71. data/pages/InstallOptions.md +20 -0
  72. data/pages/Options.md +4 -0
  73. metadata +46 -121
  74. data/test/_test_active.rb +0 -76
  75. data/test/_test_active_mimic.rb +0 -96
  76. data/test/_test_mimic_rails.rb +0 -126
  77. data/test/activerecord/result_test.rb +0 -32
  78. data/test/activesupport4/decoding_test.rb +0 -108
  79. data/test/activesupport4/encoding_test.rb +0 -531
  80. data/test/activesupport4/test_helper.rb +0 -41
  81. data/test/activesupport5/abstract_unit.rb +0 -45
  82. data/test/activesupport5/decoding_test.rb +0 -133
  83. data/test/activesupport5/encoding_test.rb +0 -500
  84. data/test/activesupport5/encoding_test_cases.rb +0 -98
  85. data/test/activesupport5/test_helper.rb +0 -72
  86. data/test/activesupport5/time_zone_test_helpers.rb +0 -39
  87. data/test/activesupport6/abstract_unit.rb +0 -44
  88. data/test/activesupport6/decoding_test.rb +0 -133
  89. data/test/activesupport6/encoding_test.rb +0 -507
  90. data/test/activesupport6/encoding_test_cases.rb +0 -98
  91. data/test/activesupport6/test_common.rb +0 -17
  92. data/test/activesupport6/test_helper.rb +0 -163
  93. data/test/activesupport6/time_zone_test_helpers.rb +0 -39
  94. data/test/activesupport7/abstract_unit.rb +0 -49
  95. data/test/activesupport7/decoding_test.rb +0 -125
  96. data/test/activesupport7/encoding_test.rb +0 -486
  97. data/test/activesupport7/encoding_test_cases.rb +0 -104
  98. data/test/activesupport7/time_zone_test_helpers.rb +0 -47
  99. data/test/bar.rb +0 -11
  100. data/test/baz.rb +0 -16
  101. data/test/bug.rb +0 -16
  102. data/test/files.rb +0 -29
  103. data/test/foo.rb +0 -77
  104. data/test/helper.rb +0 -42
  105. data/test/isolated/shared.rb +0 -308
  106. data/test/isolated/test_mimic_after.rb +0 -13
  107. data/test/isolated/test_mimic_alone.rb +0 -12
  108. data/test/isolated/test_mimic_as_json.rb +0 -45
  109. data/test/isolated/test_mimic_before.rb +0 -13
  110. data/test/isolated/test_mimic_define.rb +0 -28
  111. data/test/isolated/test_mimic_rails_after.rb +0 -22
  112. data/test/isolated/test_mimic_rails_before.rb +0 -21
  113. data/test/isolated/test_mimic_redefine.rb +0 -15
  114. data/test/json_gem/json_addition_test.rb +0 -216
  115. data/test/json_gem/json_common_interface_test.rb +0 -153
  116. data/test/json_gem/json_encoding_test.rb +0 -107
  117. data/test/json_gem/json_ext_parser_test.rb +0 -20
  118. data/test/json_gem/json_fixtures_test.rb +0 -35
  119. data/test/json_gem/json_generator_test.rb +0 -396
  120. data/test/json_gem/json_generic_object_test.rb +0 -90
  121. data/test/json_gem/json_parser_test.rb +0 -477
  122. data/test/json_gem/json_string_matching_test.rb +0 -42
  123. data/test/json_gem/test_helper.rb +0 -30
  124. data/test/mem.rb +0 -33
  125. data/test/perf.rb +0 -107
  126. data/test/perf_compat.rb +0 -130
  127. data/test/perf_dump.rb +0 -50
  128. data/test/perf_fast.rb +0 -164
  129. data/test/perf_file.rb +0 -64
  130. data/test/perf_object.rb +0 -138
  131. data/test/perf_once.rb +0 -58
  132. data/test/perf_parser.rb +0 -189
  133. data/test/perf_saj.rb +0 -109
  134. data/test/perf_scp.rb +0 -152
  135. data/test/perf_simple.rb +0 -287
  136. data/test/perf_strict.rb +0 -139
  137. data/test/perf_wab.rb +0 -131
  138. data/test/prec.rb +0 -23
  139. data/test/sample/change.rb +0 -14
  140. data/test/sample/dir.rb +0 -19
  141. data/test/sample/doc.rb +0 -36
  142. data/test/sample/file.rb +0 -48
  143. data/test/sample/group.rb +0 -16
  144. data/test/sample/hasprops.rb +0 -16
  145. data/test/sample/layer.rb +0 -12
  146. data/test/sample/line.rb +0 -20
  147. data/test/sample/oval.rb +0 -10
  148. data/test/sample/rect.rb +0 -10
  149. data/test/sample/shape.rb +0 -35
  150. data/test/sample/text.rb +0 -20
  151. data/test/sample.rb +0 -54
  152. data/test/sample_json.rb +0 -37
  153. data/test/test_compat.rb +0 -540
  154. data/test/test_custom.rb +0 -544
  155. data/test/test_debian.rb +0 -53
  156. data/test/test_fast.rb +0 -530
  157. data/test/test_file.rb +0 -255
  158. data/test/test_gc.rb +0 -60
  159. data/test/test_generate.rb +0 -21
  160. data/test/test_hash.rb +0 -39
  161. data/test/test_integer_range.rb +0 -72
  162. data/test/test_null.rb +0 -376
  163. data/test/test_object.rb +0 -1025
  164. data/test/test_parser.rb +0 -11
  165. data/test/test_parser_debug.rb +0 -27
  166. data/test/test_parser_saj.rb +0 -335
  167. data/test/test_parser_usual.rb +0 -217
  168. data/test/test_rails.rb +0 -35
  169. data/test/test_saj.rb +0 -186
  170. data/test/test_scp.rb +0 -431
  171. data/test/test_strict.rb +0 -435
  172. data/test/test_various.rb +0 -752
  173. data/test/test_wab.rb +0 -309
  174. data/test/test_writer.rb +0 -380
  175. data/test/tests.rb +0 -33
  176. data/test/tests_mimic.rb +0 -23
  177. data/test/tests_mimic_addition.rb +0 -16
  178. data/test/zoo.rb +0 -13
data/test/test_strict.rb DELETED
@@ -1,435 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- $: << File.dirname(__FILE__)
5
- $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
6
- %w(lib ext).each do |dir|
7
- $: << File.join($oj_dir, dir)
8
- end
9
-
10
- require 'minitest'
11
- require 'minitest/autorun'
12
- require 'stringio'
13
- require 'date'
14
- require 'bigdecimal'
15
- require 'oj'
16
-
17
- class StrictJuice < Minitest::Test
18
-
19
- module TestModule
20
- end
21
-
22
- class Jeez
23
- attr_accessor :x, :y
24
-
25
- def initialize(x, y)
26
- @x = x
27
- @y = y
28
- end
29
- end
30
-
31
- def setup
32
- @default_options = Oj.default_options
33
- # in strict mode other options other than the number formats are not used.
34
- Oj.default_options = { :mode => :strict }
35
- end
36
-
37
- def teardown
38
- Oj.default_options = @default_options
39
- end
40
-
41
- def test_nil
42
- dump_and_load(nil, false)
43
- end
44
-
45
- def test_true
46
- dump_and_load(true, false)
47
- end
48
-
49
- def test_false
50
- dump_and_load(false, false)
51
- end
52
-
53
- def test_fixnum
54
- dump_and_load(0, false)
55
- dump_and_load(12345, false)
56
- dump_and_load(-54321, false)
57
- dump_and_load(1, false)
58
- end
59
-
60
- def test_float
61
- dump_and_load(0.0, false)
62
- dump_and_load(12345.6789, false)
63
- dump_and_load(70.35, false)
64
- dump_and_load(-54321.012, false)
65
- dump_and_load(1.7775, false)
66
- dump_and_load(2.5024, false)
67
- dump_and_load(2.48e16, false)
68
- dump_and_load(2.48e100 * 1.0e10, false)
69
- dump_and_load(-2.48e100 * 1.0e10, false)
70
- end
71
-
72
- def test_nan_dump
73
- assert_equal('null', Oj.dump(0/0.0, :nan => :null))
74
- assert_equal('3.3e14159265358979323846', Oj.dump(0/0.0, :nan => :huge))
75
- begin
76
- Oj.dump(0/0.0, :nan => :word)
77
- rescue Exception
78
- assert(true)
79
- return
80
- end
81
- assert(false, "*** expected an exception")
82
- end
83
-
84
- def test_infinity_dump
85
- assert_equal('null', Oj.dump(1/0.0, :nan => :null))
86
- assert_equal('3.0e14159265358979323846', Oj.dump(1/0.0, :nan => :huge))
87
- begin
88
- Oj.dump(1/0.0, :nan => :word)
89
- rescue Exception
90
- assert(true)
91
- return
92
- end
93
- assert(false, "*** expected an exception")
94
- end
95
-
96
- def test_neg_infinity_dump
97
- assert_equal('null', Oj.dump(-1/0.0, :nan => :null))
98
- assert_equal('-3.0e14159265358979323846', Oj.dump(-1/0.0, :nan => :huge))
99
- begin
100
- Oj.dump(-1/0.0, :nan => :word)
101
- rescue Exception
102
- assert(true)
103
- return
104
- end
105
- assert(false, "*** expected an exception")
106
- end
107
-
108
- def test_string
109
- dump_and_load('', false)
110
- dump_and_load('abc', false)
111
- dump_and_load("abc\ndef", false)
112
- dump_and_load("a\u0041", false)
113
- end
114
-
115
- def test_encode
116
- opts = Oj.default_options
117
- Oj.default_options = { :ascii_only => false }
118
- unless 'jruby' == $ruby
119
- dump_and_load("ぴーたー", false)
120
- end
121
- Oj.default_options = { :ascii_only => true }
122
- json = Oj.dump("ぴーたー")
123
- assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
124
- unless 'jruby' == $ruby
125
- dump_and_load("ぴーたー", false)
126
- end
127
- Oj.default_options = opts
128
- end
129
-
130
- def test_unicode
131
- # hits the 3 normal ranges and one extended surrogate pair
132
- json = %{"\\u019f\\u05e9\\u3074\\ud834\\udd1e"}
133
- obj = Oj.load(json)
134
- json2 = Oj.dump(obj, :ascii_only => true)
135
- assert_equal(json, json2)
136
- end
137
-
138
- def test_unicode_long
139
- # tests buffer overflow
140
- json = %{"\\u019f\\u05e9\\u3074\\ud834\\udd1e #{'x' * 2000}"}
141
- obj = Oj.load(json)
142
- json2 = Oj.dump(obj, :ascii_only => true)
143
- assert_equal(json, json2)
144
- end
145
-
146
- def test_array
147
- dump_and_load([], false)
148
- dump_and_load([true, false], false)
149
- dump_and_load(['a', 1, nil], false)
150
- dump_and_load([[nil]], false)
151
- dump_and_load([[nil], 58], false)
152
- end
153
-
154
- def test_array_deep
155
- dump_and_load([1,[2,[3,[4,[5,[6,[7,[8,[9,[10,[11,[12,[13,[14,[15,[16,[17,[18,[19,[20]]]]]]]]]]]]]]]]]]]], false)
156
- end
157
-
158
- def test_deep_nest
159
- skip 'TruffleRuby causes SEGV' if RUBY_ENGINE == 'truffleruby'
160
-
161
- begin
162
- n = 10000
163
- Oj.strict_load('[' * n + ']' * n)
164
- rescue Exception => e
165
- assert(false, e.message)
166
- end
167
- end
168
-
169
- # Hash
170
- def test_hash
171
- dump_and_load({}, false)
172
- dump_and_load({ 'true' => true, 'false' => false}, false)
173
- dump_and_load({ 'true' => true, 'array' => [], 'hash' => { }}, false)
174
- end
175
-
176
- def test_hash_deep
177
- dump_and_load({'1' => {
178
- '2' => {
179
- '3' => {
180
- '4' => {
181
- '5' => {
182
- '6' => {
183
- '7' => {
184
- '8' => {
185
- '9' => {
186
- '10' => {
187
- '11' => {
188
- '12' => {
189
- '13' => {
190
- '14' => {
191
- '15' => {
192
- '16' => {
193
- '17' => {
194
- '18' => {
195
- '19' => {
196
- '20' => {}}}}}}}}}}}}}}}}}}}}}, false)
197
- end
198
-
199
- def test_hash_escaped_key
200
- json = %{{"a\nb":true,"c\td":false}}
201
- obj = Oj.strict_load(json)
202
- assert_equal({"a\nb" => true, "c\td" => false}, obj)
203
- end
204
-
205
- def test_non_str_hash
206
- begin
207
- Oj.dump({ 1 => true, 0 => false })
208
- rescue Exception
209
- assert(true)
210
- return
211
- end
212
- assert(false, "*** expected an exception")
213
- end
214
-
215
- def test_bignum_object
216
- dump_and_load(7 ** 55, false)
217
- end
218
-
219
- # BigDecimal
220
- def test_bigdecimal_strict
221
- Oj.default_options = { :bigdecimal_load => true}
222
- dump_and_load(BigDecimal('3.14159265358979323846'), false)
223
- end
224
-
225
- def test_bigdecimal_load
226
- orig = BigDecimal('80.51')
227
- json = Oj.dump(orig, :mode => :strict, :bigdecimal_as_decimal => true)
228
- bg = Oj.load(json, :mode => :strict, :bigdecimal_load => true)
229
- assert_equal(BigDecimal, bg.class)
230
- assert_equal(orig, bg)
231
- end
232
-
233
- def test_json_object
234
- obj = Jeez.new(true, 58)
235
- begin
236
- Oj.dump(obj)
237
- rescue Exception
238
- assert(true)
239
- return
240
- end
241
- assert(false, "*** expected an exception")
242
- end
243
-
244
- def test_range
245
- begin
246
- Oj.dump(1..7)
247
- rescue Exception
248
- assert(true)
249
- return
250
- end
251
- assert(false, "*** expected an exception")
252
- end
253
-
254
- # Stream IO
255
- def test_io_string
256
- json = %{{
257
- "x":true,
258
- "y":58,
259
- "z": [1,2,3]
260
- }
261
- }
262
- input = StringIO.new(json)
263
- obj = Oj.strict_load(input)
264
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
265
- end
266
-
267
- def test_io_file
268
- filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
269
- File.open(filename, 'w') { |f| f.write(%{{
270
- "x":true,
271
- "y":58,
272
- "z": [1,2,3]
273
- }
274
- }) }
275
- f = File.new(filename)
276
- obj = Oj.strict_load(f)
277
- f.close()
278
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
279
- end
280
-
281
- def test_symbol
282
- json = Oj.dump(:abc)
283
- assert_equal('"abc"', json)
284
- end
285
-
286
- def test_time
287
- t = Time.local(2012, 1, 5, 23, 58, 7)
288
- begin
289
- Oj.dump(t)
290
- rescue Exception
291
- assert(true)
292
- return
293
- end
294
- assert(false, "*** expected an exception")
295
- end
296
-
297
- def test_class
298
- begin
299
- Oj.dump(StrictJuice)
300
- rescue Exception
301
- assert(true)
302
- return
303
- end
304
- assert(false, "*** expected an exception")
305
- end
306
-
307
- def test_module
308
- begin
309
- Oj.dump(TestModule)
310
- rescue Exception
311
- assert(true)
312
- return
313
- end
314
- assert(false, "*** expected an exception")
315
- end
316
-
317
- # symbol_keys option
318
- def test_symbol_keys
319
- json = %{{
320
- "x":true,
321
- "y":58,
322
- "z": [1,2,3]
323
- }
324
- }
325
- obj = Oj.strict_load(json, :symbol_keys => true)
326
- assert_equal({ :x => true, :y => 58, :z => [1, 2, 3]}, obj)
327
- end
328
-
329
- def test_symbol_keys_safe
330
- json = %{{
331
- "x":true,
332
- "y":58,
333
- "z": [1,2,3]
334
- }
335
- }
336
- obj = Oj.safe_load(json)
337
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
338
- end
339
-
340
- # comments
341
- def test_comment_slash
342
- json = %{{
343
- "x":true,//three
344
- "y":58,
345
- "z": [1,2,
346
- 3 // six
347
- ]}
348
- }
349
- obj = Oj.strict_load(json)
350
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
351
- end
352
-
353
- def test_comment_c
354
- json = %{{
355
- "x"/*one*/:/*two*/true,
356
- "y":58,
357
- "z": [1,2,3]}
358
- }
359
- obj = Oj.strict_load(json)
360
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
361
- end
362
-
363
- def test_comment
364
- json = %{{
365
- "x"/*one*/:/*two*/true,//three
366
- "y":58/*four*/,
367
- "z": [1,2/*five*/,
368
- 3 // six
369
- ]
370
- }
371
- }
372
- obj = Oj.strict_load(json)
373
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
374
- end
375
-
376
- def test_double
377
- json = %{{ "x": 1}{ "y": 2}}
378
- results = []
379
- Oj.load(json, :mode => :strict) { |x| results << x }
380
-
381
- assert_equal([{ 'x' => 1 }, { 'y' => 2 }], results)
382
- end
383
-
384
- def test_invalid_decimal_dot_start
385
- assert_raises(Oj::ParseError) {
386
- Oj.load('.123', mode: :strict)
387
- }
388
- assert_raises(Oj::ParseError) {
389
- Oj.load('-.123', mode: :strict)
390
- }
391
- end
392
-
393
- def test_invalid_decimal_dot_end
394
- json = '123.'
395
- assert_raises(Oj::ParseError) {
396
- Oj.load(json, mode: :strict)
397
- }
398
- end
399
-
400
- def test_invalid_decimal_plus
401
- json = '+12'
402
- assert_raises(Oj::ParseError) {
403
- Oj.load(json, mode: :strict)
404
- }
405
- end
406
-
407
- def test_circular_hash
408
- h = { 'a' => 7 }
409
- h['b'] = h
410
- json = Oj.dump(h, :indent => 2, :circular => true)
411
- assert_equal(%|{
412
- "a":7,
413
- "b":null
414
- }
415
- |, json)
416
- end
417
-
418
- def test_omit_nil
419
- json = Oj.dump({'x' => {'a' => 1, 'b' => nil }, 'y' => nil}, :omit_nil => true)
420
- assert_equal(%|{"x":{"a":1}}|, json)
421
- end
422
-
423
- def dump_and_load(obj, trace=false)
424
- json = Oj.dump(obj, :indent => 2)
425
- puts json if trace
426
- loaded = Oj.strict_load(json);
427
- if obj.nil?
428
- assert_nil(loaded)
429
- else
430
- assert_equal(obj, loaded)
431
- end
432
- loaded
433
- end
434
-
435
- end