oj 3.13.14 → 3.13.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/README.md +2 -0
  4. data/ext/oj/buf.h +4 -0
  5. data/ext/oj/compat.c +10 -10
  6. data/ext/oj/custom.c +34 -53
  7. data/ext/oj/dump.c +24 -13
  8. data/ext/oj/dump_compat.c +5 -10
  9. data/ext/oj/dump_object.c +5 -60
  10. data/ext/oj/dump_strict.c +5 -5
  11. data/ext/oj/extconf.rb +5 -4
  12. data/ext/oj/fast.c +15 -13
  13. data/ext/oj/intern.c +6 -9
  14. data/ext/oj/introspect.c +96 -0
  15. data/ext/oj/mimic_json.c +18 -8
  16. data/ext/oj/object.c +42 -41
  17. data/ext/oj/oj.c +27 -4
  18. data/ext/oj/oj.h +4 -1
  19. data/ext/oj/parse.c +111 -76
  20. data/ext/oj/parse.h +2 -0
  21. data/ext/oj/parser.c +61 -4
  22. data/ext/oj/parser.h +12 -0
  23. data/ext/oj/rails.c +5 -10
  24. data/ext/oj/saj2.c +333 -85
  25. data/ext/oj/saj2.h +23 -0
  26. data/ext/oj/sparse.c +4 -0
  27. data/ext/oj/strict.c +13 -13
  28. data/ext/oj/usual.c +82 -129
  29. data/ext/oj/usual.h +68 -0
  30. data/ext/oj/val_stack.c +1 -1
  31. data/ext/oj/validate.c +21 -26
  32. data/ext/oj/wab.c +15 -20
  33. data/lib/oj/saj.rb +20 -6
  34. data/lib/oj/state.rb +1 -1
  35. data/lib/oj/version.rb +1 -1
  36. data/pages/Compatibility.md +1 -1
  37. data/test/bar.rb +3 -1
  38. data/test/helper.rb +8 -2
  39. data/test/json_gem/json_generator_test.rb +3 -4
  40. data/test/json_gem/json_parser_test.rb +8 -1
  41. data/test/json_gem/test_helper.rb +7 -3
  42. data/test/test_compat.rb +25 -0
  43. data/test/test_custom.rb +13 -2
  44. data/test/test_file.rb +23 -7
  45. data/test/test_gc.rb +11 -0
  46. data/test/test_object.rb +3 -10
  47. data/test/test_parser.rb +3 -19
  48. data/test/test_parser_debug.rb +27 -0
  49. data/test/test_parser_saj.rb +92 -2
  50. data/test/test_scp.rb +2 -4
  51. data/test/test_strict.rb +2 -0
  52. data/test/test_various.rb +8 -3
  53. data/test/test_wab.rb +2 -0
  54. data/test/tests.rb +9 -0
  55. data/test/tests_mimic.rb +9 -0
  56. data/test/tests_mimic_addition.rb +9 -0
  57. metadata +7 -107
@@ -0,0 +1,27 @@
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 ParserJuice < Minitest::Test
18
+
19
+ def test_array
20
+ p = Oj::Parser.new(:debug)
21
+ out = p.parse(%|[true, false, null, 123, -1.23, "abc"]|)
22
+ puts out
23
+ out = p.parse(%|{"abc": []}|)
24
+ puts out
25
+ end
26
+
27
+ end
@@ -5,7 +5,7 @@ $: << File.dirname(__FILE__)
5
5
 
6
6
  require 'helper'
7
7
 
8
- $json = %{{
8
+ $json = %|{
9
9
  "array": [
10
10
  {
11
11
  "num" : 3,
@@ -18,7 +18,7 @@ $json = %{{
18
18
  }
19
19
  ],
20
20
  "boolean" : true
21
- }}
21
+ }|
22
22
 
23
23
  class AllSaj < Oj::Saj
24
24
  attr_accessor :calls
@@ -53,6 +53,35 @@ class AllSaj < Oj::Saj
53
53
 
54
54
  end # AllSaj
55
55
 
56
+ class LocSaj
57
+ attr_accessor :calls
58
+
59
+ def initialize()
60
+ @calls = []
61
+ end
62
+
63
+ def hash_start(key, line, column)
64
+ @calls << [:hash_start, key, line, column]
65
+ end
66
+
67
+ def hash_end(key, line, column)
68
+ @calls << [:hash_end, key, line, column]
69
+ end
70
+
71
+ def array_start(key, line, column)
72
+ @calls << [:array_start, key, line, column]
73
+ end
74
+
75
+ def array_end(key, line, column)
76
+ @calls << [:array_end, key, line, column]
77
+ end
78
+
79
+ def add_value(value, key, line, column)
80
+ @calls << [:add_value, value, key, line, column]
81
+ end
82
+
83
+ end # LocSaj
84
+
56
85
  class SajTest < Minitest::Test
57
86
 
58
87
  def test_nil
@@ -120,6 +149,43 @@ class SajTest < Minitest::Test
120
149
  assert_equal((12345.6789e7 * 10000).to_i, (handler.calls[0][1] * 10000).to_i)
121
150
  end
122
151
 
152
+ def test_bignum
153
+ handler = AllSaj.new()
154
+ json = %{-11.899999999999999}
155
+ p = Oj::Parser.new(:saj)
156
+ p.handler = handler
157
+ p.parse(json)
158
+ assert_equal(1, handler.calls.size)
159
+ assert_equal(:add_value, handler.calls[0][0])
160
+ assert_equal(-118999, (handler.calls[0][1] * 10000).to_i)
161
+ end
162
+
163
+ def test_bignum_loc
164
+ handler = LocSaj.new()
165
+ json = <<~JSON
166
+ {
167
+ "width": 192.33800000000002,
168
+ "xaxis": {
169
+ "anchor": "y"
170
+ }
171
+ }
172
+ JSON
173
+
174
+ p = Oj::Parser.new(:saj)
175
+ p.handler = handler
176
+ p.parse(json)
177
+ assert_equal(6, handler.calls.size)
178
+ assert_equal(1_923_380, (handler.calls[1][1] * 10000).to_i)
179
+ handler.calls[1][1] = 1_923_380
180
+ assert_equal([[:hash_start, nil, 1, 1],
181
+ [:add_value, 1923380, 'width', 2, 30],
182
+ [:hash_start, 'xaxis', 3, 12],
183
+ [:add_value, 'y', 'anchor', 4, 17],
184
+ [:hash_end, 'xaxis', 5, 3],
185
+ [:hash_end, nil, 6, 1]],
186
+ handler.calls)
187
+ end
188
+
123
189
  def test_array_empty
124
190
  handler = AllSaj.new()
125
191
  json = %{[]}
@@ -242,4 +308,28 @@ class SajTest < Minitest::Test
242
308
  ], handler.calls)
243
309
  end
244
310
 
311
+ def test_loc
312
+ handler = LocSaj.new()
313
+ Oj::Parser.saj.handler = handler
314
+ Oj::Parser.saj.parse($json)
315
+ assert_equal([[:hash_start, nil, 1, 1],
316
+ [:array_start, 'array', 2, 12],
317
+ [:hash_start, nil, 3, 5],
318
+ [:add_value, 3, 'num', 4, 18],
319
+ [:add_value, 'message', 'string', 5, 25],
320
+ [:hash_start, 'hash', 6, 17],
321
+ [:hash_start, 'h2', 7, 17],
322
+ [:array_start, 'a', 8, 17],
323
+ [:add_value, 1, nil, 8, 20],
324
+ [:add_value, 2, nil, 8, 23],
325
+ [:add_value, 3, nil, 8, 26],
326
+ [:array_end, 'a', 8, 27],
327
+ [:hash_end, 'h2', 9, 9],
328
+ [:hash_end, 'hash', 10, 7],
329
+ [:hash_end, nil, 11, 5],
330
+ [:array_end, 'array', 12, 3],
331
+ [:add_value, true, 'boolean', 13, 18],
332
+ [:hash_end, nil, 14, 1]], handler.calls)
333
+ end
334
+
245
335
  end
data/test/test_scp.rb CHANGED
@@ -320,8 +320,7 @@ class ScpTest < Minitest::Test
320
320
  end
321
321
 
322
322
  def test_pipe
323
- # Windows does not support fork
324
- return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
323
+ skip 'needs fork' unless Process.respond_to?(:fork)
325
324
 
326
325
  handler = AllHandler.new()
327
326
  json = %{{"one":true,"two":false}}
@@ -357,8 +356,7 @@ class ScpTest < Minitest::Test
357
356
  end
358
357
 
359
358
  def test_pipe_close
360
- # Windows does not support fork
361
- return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
359
+ skip 'needs fork' unless Process.respond_to?(:fork)
362
360
 
363
361
  json = %{{"one":true,"two":false}}
364
362
  IO.pipe do |read_io, write_io|
data/test/test_strict.rb CHANGED
@@ -156,6 +156,8 @@ class StrictJuice < Minitest::Test
156
156
  end
157
157
 
158
158
  def test_deep_nest
159
+ skip 'TruffleRuby causes SEGV' if RUBY_ENGINE == 'truffleruby'
160
+
159
161
  begin
160
162
  n = 10000
161
163
  Oj.strict_load('[' * n + ']' * n)
data/test/test_various.rb CHANGED
@@ -345,6 +345,12 @@ class Juice < Minitest::Test
345
345
  out = Oj.dump hash
346
346
  assert_equal(%{{"key":"I \\u003c3 this"}}, out)
347
347
  end
348
+ def test_escapes_slashes_by_default_when_configured_to_do_so
349
+ hash = {'key' => "I <3 this </script>"}
350
+ Oj.default_options = {:escape_mode => :slash}
351
+ out = Oj.dump hash
352
+ assert_equal(%{{"key":"I <3 this <\\/script>"}}, out)
353
+ end
348
354
  def test_escapes_entities_when_asked_to
349
355
  hash = {'key' => "I <3 this"}
350
356
  out = Oj.dump(hash, :escape_mode => :xss_safe)
@@ -553,9 +559,6 @@ class Juice < Minitest::Test
553
559
  end
554
560
 
555
561
  def test_io_file
556
- # Windows does not support fork
557
- return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
558
-
559
562
  src = { 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}
560
563
  filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
561
564
  File.open(filename, "w") { |f|
@@ -568,6 +571,8 @@ class Juice < Minitest::Test
568
571
  end
569
572
 
570
573
  def test_io_stream
574
+ skip 'needs fork' unless Process.respond_to?(:fork)
575
+
571
576
  IO.pipe do |r, w|
572
577
  if fork
573
578
  r.close
data/test/test_wab.rb CHANGED
@@ -105,6 +105,8 @@ class WabJuice < Minitest::Test
105
105
  end
106
106
 
107
107
  def test_deep_nest
108
+ skip 'TruffleRuby causes SEGV' if RUBY_ENGINE == 'truffleruby'
109
+
108
110
  begin
109
111
  n = 10000
110
112
  Oj.wab_load('[' * n + ']' * n)
data/test/tests.rb CHANGED
@@ -22,3 +22,12 @@ require 'test_rails'
22
22
  require 'test_wab'
23
23
  require 'test_writer'
24
24
  require 'test_integer_range'
25
+
26
+ at_exit do
27
+ require 'helper'
28
+ if '3.1.0' <= RUBY_VERSION && !(RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/)
29
+ #Oj::debug_odd("teardown before GC.verify_compaction_references")
30
+ verify_gc_compaction
31
+ #Oj::debug_odd("teardown after GC.verify_compaction_references")
32
+ end
33
+ end
data/test/tests_mimic.rb CHANGED
@@ -12,3 +12,12 @@ require 'json_generator_test'
12
12
  require 'json_generic_object_test'
13
13
  require 'json_parser_test'
14
14
  require 'json_string_matching_test'
15
+
16
+ at_exit do
17
+ require 'helper'
18
+ if '3.1.0' <= RUBY_VERSION && !(RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/)
19
+ #Oj::debug_odd("teardown before GC.verify_compaction_references")
20
+ verify_gc_compaction
21
+ #Oj::debug_odd("teardown after GC.verify_compaction_references")
22
+ end
23
+ end
@@ -5,3 +5,12 @@ $: << File.dirname(__FILE__)
5
5
  $: << File.join(File.dirname(__FILE__), 'json_gem')
6
6
 
7
7
  require 'json_addition_test'
8
+
9
+ at_exit do
10
+ require 'helper'
11
+ if '3.1.0' <= RUBY_VERSION && !(RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/)
12
+ #Oj::debug_odd("teardown before GC.verify_compaction_references")
13
+ verify_gc_compaction
14
+ #Oj::debug_odd("teardown after GC.verify_compaction_references")
15
+ end
16
+ end
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.13.14
4
+ version: 3.13.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-03 00:00:00.000000000 Z
11
+ date: 2022-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -110,6 +110,7 @@ files:
110
110
  - ext/oj/fast.c
111
111
  - ext/oj/intern.c
112
112
  - ext/oj/intern.h
113
+ - ext/oj/introspect.c
113
114
  - ext/oj/mimic_json.c
114
115
  - ext/oj/object.c
115
116
  - ext/oj/odd.c
@@ -130,6 +131,7 @@ files:
130
131
  - ext/oj/rxclass.h
131
132
  - ext/oj/saj.c
132
133
  - ext/oj/saj2.c
134
+ - ext/oj/saj2.h
133
135
  - ext/oj/scp.c
134
136
  - ext/oj/sparse.c
135
137
  - ext/oj/stream_writer.c
@@ -138,6 +140,7 @@ files:
138
140
  - ext/oj/trace.c
139
141
  - ext/oj/trace.h
140
142
  - ext/oj/usual.c
143
+ - ext/oj/usual.h
141
144
  - ext/oj/util.c
142
145
  - ext/oj/util.h
143
146
  - ext/oj/val_stack.c
@@ -257,6 +260,7 @@ files:
257
260
  - test/test_null.rb
258
261
  - test/test_object.rb
259
262
  - test/test_parser.rb
263
+ - test/test_parser_debug.rb
260
264
  - test/test_parser_saj.rb
261
265
  - test/test_parser_usual.rb
262
266
  - test/test_rails.rb
@@ -303,108 +307,4 @@ rubygems_version: 3.3.3
303
307
  signing_key:
304
308
  specification_version: 4
305
309
  summary: A fast JSON parser and serializer.
306
- test_files:
307
- - test/_test_active.rb
308
- - test/_test_active_mimic.rb
309
- - test/_test_mimic_rails.rb
310
- - test/activerecord/result_test.rb
311
- - test/activesupport4/decoding_test.rb
312
- - test/activesupport4/encoding_test.rb
313
- - test/activesupport4/test_helper.rb
314
- - test/activesupport5/abstract_unit.rb
315
- - test/activesupport5/decoding_test.rb
316
- - test/activesupport5/encoding_test.rb
317
- - test/activesupport5/encoding_test_cases.rb
318
- - test/activesupport5/test_helper.rb
319
- - test/activesupport5/time_zone_test_helpers.rb
320
- - test/activesupport6/abstract_unit.rb
321
- - test/activesupport6/decoding_test.rb
322
- - test/activesupport6/encoding_test.rb
323
- - test/activesupport6/encoding_test_cases.rb
324
- - test/activesupport6/test_common.rb
325
- - test/activesupport6/test_helper.rb
326
- - test/activesupport6/time_zone_test_helpers.rb
327
- - test/activesupport7/abstract_unit.rb
328
- - test/activesupport7/decoding_test.rb
329
- - test/activesupport7/encoding_test.rb
330
- - test/activesupport7/encoding_test_cases.rb
331
- - test/activesupport7/time_zone_test_helpers.rb
332
- - test/bar.rb
333
- - test/baz.rb
334
- - test/bug.rb
335
- - test/files.rb
336
- - test/foo.rb
337
- - test/helper.rb
338
- - test/isolated/shared.rb
339
- - test/isolated/test_mimic_after.rb
340
- - test/isolated/test_mimic_alone.rb
341
- - test/isolated/test_mimic_as_json.rb
342
- - test/isolated/test_mimic_before.rb
343
- - test/isolated/test_mimic_define.rb
344
- - test/isolated/test_mimic_rails_after.rb
345
- - test/isolated/test_mimic_rails_before.rb
346
- - test/isolated/test_mimic_redefine.rb
347
- - test/json_gem/json_addition_test.rb
348
- - test/json_gem/json_common_interface_test.rb
349
- - test/json_gem/json_encoding_test.rb
350
- - test/json_gem/json_ext_parser_test.rb
351
- - test/json_gem/json_fixtures_test.rb
352
- - test/json_gem/json_generator_test.rb
353
- - test/json_gem/json_generic_object_test.rb
354
- - test/json_gem/json_parser_test.rb
355
- - test/json_gem/json_string_matching_test.rb
356
- - test/json_gem/test_helper.rb
357
- - test/mem.rb
358
- - test/perf.rb
359
- - test/perf_compat.rb
360
- - test/perf_dump.rb
361
- - test/perf_fast.rb
362
- - test/perf_file.rb
363
- - test/perf_object.rb
364
- - test/perf_once.rb
365
- - test/perf_parser.rb
366
- - test/perf_saj.rb
367
- - test/perf_scp.rb
368
- - test/perf_simple.rb
369
- - test/perf_strict.rb
370
- - test/perf_wab.rb
371
- - test/prec.rb
372
- - test/sample/change.rb
373
- - test/sample/dir.rb
374
- - test/sample/doc.rb
375
- - test/sample/file.rb
376
- - test/sample/group.rb
377
- - test/sample/hasprops.rb
378
- - test/sample/layer.rb
379
- - test/sample/line.rb
380
- - test/sample/oval.rb
381
- - test/sample/rect.rb
382
- - test/sample/shape.rb
383
- - test/sample/text.rb
384
- - test/sample.rb
385
- - test/sample_json.rb
386
- - test/test_compat.rb
387
- - test/test_custom.rb
388
- - test/test_debian.rb
389
- - test/test_fast.rb
390
- - test/test_file.rb
391
- - test/test_gc.rb
392
- - test/test_generate.rb
393
- - test/test_hash.rb
394
- - test/test_integer_range.rb
395
- - test/test_null.rb
396
- - test/test_object.rb
397
- - test/test_parser.rb
398
- - test/test_parser_saj.rb
399
- - test/test_parser_usual.rb
400
- - test/test_rails.rb
401
- - test/test_saj.rb
402
- - test/test_scp.rb
403
- - test/test_strict.rb
404
- - test/test_various.rb
405
- - test/test_wab.rb
406
- - test/test_writer.rb
407
- - test/tests.rb
408
- - test/tests_mimic.rb
409
- - test/tests_mimic_addition.rb
410
- - test/zoo.rb
310
+ test_files: []