oj 3.14.3 → 3.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/ext/oj/code.c +3 -10
- data/ext/oj/compat.c +5 -18
- data/ext/oj/custom.c +10 -28
- data/ext/oj/dump.c +40 -10
- data/ext/oj/dump.h +1 -4
- data/ext/oj/extconf.rb +4 -2
- data/ext/oj/fast.c +3 -6
- data/ext/oj/mimic_json.c +21 -1
- data/ext/oj/object.c +7 -21
- data/ext/oj/oj.c +24 -4
- data/ext/oj/oj.h +10 -6
- data/ext/oj/parse.c +3 -5
- data/ext/oj/parse.h +16 -14
- data/ext/oj/parser.h +2 -2
- data/ext/oj/reader.c +1 -3
- data/ext/oj/saj.c +1 -1
- data/ext/oj/strict.c +9 -27
- data/ext/oj/wab.c +9 -27
- data/lib/oj/active_support_helper.rb +2 -3
- data/lib/oj/json.rb +156 -149
- data/lib/oj/mimic.rb +3 -1
- data/lib/oj/version.rb +1 -1
- data/lib/oj.rb +3 -0
- data/pages/Options.md +4 -0
- data/test/_test_active.rb +8 -8
- data/test/_test_active_mimic.rb +7 -7
- data/test/_test_mimic_rails.rb +17 -19
- data/test/files.rb +14 -14
- data/test/foo.rb +15 -10
- data/test/helper.rb +4 -4
- data/test/mem.rb +8 -7
- data/test/perf.rb +21 -26
- data/test/perf_compat.rb +30 -32
- data/test/perf_dump.rb +27 -27
- data/test/perf_fast.rb +80 -82
- data/test/perf_file.rb +27 -29
- data/test/perf_object.rb +65 -68
- data/test/perf_once.rb +8 -7
- data/test/perf_parser.rb +40 -46
- data/test/perf_saj.rb +46 -53
- data/test/perf_scp.rb +57 -69
- data/test/perf_simple.rb +40 -38
- data/test/perf_strict.rb +68 -70
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +3 -3
- data/test/sample.rb +16 -15
- data/test/sample_json.rb +8 -7
- data/test/test_compat.rb +44 -46
- data/test/test_custom.rb +56 -42
- data/test/test_debian.rb +6 -9
- data/test/test_fast.rb +78 -72
- data/test/test_file.rb +16 -21
- data/test/test_gc.rb +5 -5
- data/test/test_generate.rb +5 -5
- data/test/test_hash.rb +4 -4
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +18 -20
- data/test/test_object.rb +76 -86
- data/test/test_parser.rb +4 -4
- data/test/test_parser_debug.rb +4 -4
- data/test/test_parser_saj.rb +31 -31
- data/test/test_parser_usual.rb +3 -3
- data/test/test_rails.rb +2 -2
- data/test/test_saj.rb +8 -8
- data/test/test_scp.rb +29 -29
- data/test/test_strict.rb +25 -31
- data/test/test_various.rb +121 -75
- data/test/test_wab.rb +43 -42
- data/test/test_writer.rb +46 -46
- data/test/tests.rb +7 -7
- data/test/tests_mimic.rb +6 -6
- data/test/tests_mimic_addition.rb +6 -6
- metadata +3 -6
- data/test/bar.rb +0 -11
- data/test/baz.rb +0 -16
- data/test/bug.rb +0 -16
- data/test/zoo.rb +0 -13
data/test/test_writer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: false
|
3
3
|
|
4
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
5
|
|
6
6
|
require 'helper'
|
7
7
|
|
@@ -55,13 +55,13 @@ class OjWriter < Minitest::Test
|
|
55
55
|
def test_string_writer_nested_object
|
56
56
|
w = Oj::StringWriter.new(:indent => 0)
|
57
57
|
w.push_object()
|
58
|
-
w.push_object(
|
58
|
+
w.push_object('a1')
|
59
59
|
w.pop()
|
60
|
-
w.push_object(
|
61
|
-
w.push_object(
|
60
|
+
w.push_object('a2')
|
61
|
+
w.push_object('b')
|
62
62
|
w.pop()
|
63
63
|
w.pop()
|
64
|
-
w.push_object(
|
64
|
+
w.push_object('a3')
|
65
65
|
w.pop()
|
66
66
|
w.pop()
|
67
67
|
assert_equal(%|{"a1":{},"a2":{"b":{}},"a3":{}}\n|, w.to_s)
|
@@ -94,7 +94,7 @@ class OjWriter < Minitest::Test
|
|
94
94
|
w.push_value(7.3)
|
95
95
|
w.push_value(true)
|
96
96
|
w.push_value(nil)
|
97
|
-
w.push_value(
|
97
|
+
w.push_value('a string')
|
98
98
|
w.push_value({'a' => 65})
|
99
99
|
w.push_value([1, 2])
|
100
100
|
w.pop()
|
@@ -118,10 +118,10 @@ class OjWriter < Minitest::Test
|
|
118
118
|
def test_string_writer_block
|
119
119
|
w = Oj::StringWriter.new(:indent => 0)
|
120
120
|
w.push_object() {
|
121
|
-
w.push_object(
|
121
|
+
w.push_object('a1') {
|
122
122
|
w.push_value(7, 'a7')
|
123
123
|
}
|
124
|
-
w.push_array(
|
124
|
+
w.push_array('a2') {
|
125
125
|
w.push_value('x')
|
126
126
|
w.push_value(3)
|
127
127
|
}
|
@@ -152,7 +152,7 @@ class OjWriter < Minitest::Test
|
|
152
152
|
assert(true)
|
153
153
|
return
|
154
154
|
end
|
155
|
-
assert(false,
|
155
|
+
assert(false, '*** expected an exception')
|
156
156
|
end
|
157
157
|
|
158
158
|
def test_string_writer_array_key
|
@@ -166,7 +166,7 @@ class OjWriter < Minitest::Test
|
|
166
166
|
assert(true)
|
167
167
|
return
|
168
168
|
end
|
169
|
-
assert(false,
|
169
|
+
assert(false, '*** expected an exception')
|
170
170
|
end
|
171
171
|
|
172
172
|
def test_string_writer_pop_with_key
|
@@ -177,7 +177,7 @@ class OjWriter < Minitest::Test
|
|
177
177
|
assert(true)
|
178
178
|
return
|
179
179
|
end
|
180
|
-
assert(false,
|
180
|
+
assert(false, '*** expected an exception')
|
181
181
|
end
|
182
182
|
|
183
183
|
def test_string_writer_obj_no_key
|
@@ -189,7 +189,7 @@ class OjWriter < Minitest::Test
|
|
189
189
|
assert(true)
|
190
190
|
return
|
191
191
|
end
|
192
|
-
assert(false,
|
192
|
+
assert(false, '*** expected an exception')
|
193
193
|
end
|
194
194
|
|
195
195
|
def test_string_writer_deep
|
@@ -208,9 +208,9 @@ class OjWriter < Minitest::Test
|
|
208
208
|
def test_string_writer_pop_all
|
209
209
|
w = Oj::StringWriter.new(:indent => 0)
|
210
210
|
w.push_object()
|
211
|
-
w.push_object(
|
211
|
+
w.push_object('a1')
|
212
212
|
w.pop()
|
213
|
-
w.push_array(
|
213
|
+
w.push_array('a2')
|
214
214
|
w.push_value(3)
|
215
215
|
w.push_array()
|
216
216
|
w.pop_all()
|
@@ -228,23 +228,23 @@ class OjWriter < Minitest::Test
|
|
228
228
|
# Stream Writer
|
229
229
|
|
230
230
|
class SString < ::String
|
231
|
-
alias
|
231
|
+
alias write concat
|
232
232
|
end
|
233
|
-
|
233
|
+
|
234
234
|
def test_stream_writer_encoding
|
235
235
|
output = SString.new.force_encoding(::Encoding::UTF_8)
|
236
236
|
w = Oj::StreamWriter.new(output, :indent => 0)
|
237
237
|
# Oddly enough, when pushing ASCII characters with UTF-8 encoding or even
|
238
238
|
# ASCII-8BIT does not change the output encoding. Pushing any non-ASCII no
|
239
239
|
# matter what the encoding changes the output encoding to ASCII-8BIT.
|
240
|
-
x =
|
240
|
+
x = '香港' # Hong Kong
|
241
241
|
x = x.force_encoding('ASCII-8BIT')
|
242
242
|
w.push_value(x)
|
243
243
|
assert_equal(::Encoding::UTF_8, output.encoding)
|
244
244
|
end
|
245
245
|
|
246
246
|
def test_stream_writer_empty_array
|
247
|
-
output = StringIO.open(
|
247
|
+
output = StringIO.open('', 'w+')
|
248
248
|
w = Oj::StreamWriter.new(output, :indent => 0)
|
249
249
|
w.push_array()
|
250
250
|
w.pop()
|
@@ -252,19 +252,19 @@ class OjWriter < Minitest::Test
|
|
252
252
|
end
|
253
253
|
|
254
254
|
def test_stream_writer_mixed_stringio
|
255
|
-
output = StringIO.open(
|
255
|
+
output = StringIO.open('', 'w+')
|
256
256
|
w = Oj::StreamWriter.new(output, :indent => 0)
|
257
257
|
w.push_object()
|
258
|
-
w.push_object(
|
258
|
+
w.push_object('a1')
|
259
259
|
w.pop()
|
260
|
-
w.push_object(
|
261
|
-
w.push_array(
|
260
|
+
w.push_object('a2')
|
261
|
+
w.push_array('b')
|
262
262
|
w.push_value(7)
|
263
263
|
w.push_value(true)
|
264
|
-
w.push_value(
|
264
|
+
w.push_value('string')
|
265
265
|
w.pop()
|
266
266
|
w.pop()
|
267
|
-
w.push_object(
|
267
|
+
w.push_object('a3')
|
268
268
|
w.pop()
|
269
269
|
w.pop()
|
270
270
|
result = output.string()
|
@@ -272,20 +272,20 @@ class OjWriter < Minitest::Test
|
|
272
272
|
end
|
273
273
|
|
274
274
|
def test_stream_writer_mixed_file
|
275
|
-
filename = File.join(
|
276
|
-
File.open(filename,
|
275
|
+
filename = File.join(__dir__, 'open_file_test.json')
|
276
|
+
File.open(filename, 'w') do |f|
|
277
277
|
w = Oj::StreamWriter.new(f, :indent => 0)
|
278
278
|
w.push_object()
|
279
|
-
w.push_object(
|
279
|
+
w.push_object('a1')
|
280
280
|
w.pop()
|
281
|
-
w.push_object(
|
282
|
-
w.push_array(
|
281
|
+
w.push_object('a2')
|
282
|
+
w.push_array('b')
|
283
283
|
w.push_value(7)
|
284
284
|
w.push_value(true)
|
285
|
-
w.push_value(
|
285
|
+
w.push_value('string')
|
286
286
|
w.pop()
|
287
287
|
w.pop()
|
288
|
-
w.push_object(
|
288
|
+
w.push_object('a3')
|
289
289
|
w.pop()
|
290
290
|
w.pop()
|
291
291
|
end
|
@@ -294,7 +294,7 @@ class OjWriter < Minitest::Test
|
|
294
294
|
end
|
295
295
|
|
296
296
|
def test_stream_writer_nested_key_object
|
297
|
-
output = StringIO.open(
|
297
|
+
output = StringIO.open('', 'w+')
|
298
298
|
w = Oj::StreamWriter.new(output, :indent => 0)
|
299
299
|
w.push_object()
|
300
300
|
w.push_key('a1')
|
@@ -316,16 +316,16 @@ class OjWriter < Minitest::Test
|
|
316
316
|
|
317
317
|
def push_stuff(w, pop_all=true)
|
318
318
|
w.push_object()
|
319
|
-
w.push_object(
|
319
|
+
w.push_object('a1')
|
320
320
|
w.pop()
|
321
|
-
w.push_object(
|
322
|
-
w.push_array(
|
321
|
+
w.push_object('a2')
|
322
|
+
w.push_array('b')
|
323
323
|
w.push_value(7)
|
324
324
|
w.push_value(true)
|
325
|
-
w.push_value(
|
325
|
+
w.push_value('string')
|
326
326
|
w.pop()
|
327
327
|
w.pop()
|
328
|
-
w.push_object(
|
328
|
+
w.push_object('a3')
|
329
329
|
if pop_all
|
330
330
|
w.pop_all()
|
331
331
|
else
|
@@ -335,31 +335,31 @@ class OjWriter < Minitest::Test
|
|
335
335
|
end
|
336
336
|
|
337
337
|
def test_stream_writer_buf_small
|
338
|
-
output = StringIO.open(
|
338
|
+
output = StringIO.open('', 'w+')
|
339
339
|
w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 20)
|
340
340
|
push_stuff(w)
|
341
341
|
assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
|
342
342
|
end
|
343
343
|
|
344
344
|
def test_stream_writer_buf_large
|
345
|
-
output = StringIO.open(
|
346
|
-
w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size =>
|
345
|
+
output = StringIO.open('', 'w+')
|
346
|
+
w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 16_000)
|
347
347
|
push_stuff(w)
|
348
348
|
assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
|
349
349
|
end
|
350
350
|
|
351
351
|
def test_stream_writer_buf_flush
|
352
|
-
output = StringIO.open(
|
352
|
+
output = StringIO.open('', 'w+')
|
353
353
|
w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 4096)
|
354
354
|
push_stuff(w, false)
|
355
355
|
# no flush so nothing should be in the output yet
|
356
|
-
assert_equal(
|
356
|
+
assert_equal('', output.string())
|
357
357
|
w.flush()
|
358
358
|
assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
|
359
359
|
end
|
360
|
-
|
360
|
+
|
361
361
|
def test_stream_writer_buf_flush_small
|
362
|
-
output = StringIO.open(
|
362
|
+
output = StringIO.open('', 'w+')
|
363
363
|
w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 30)
|
364
364
|
push_stuff(w, false)
|
365
365
|
# flush should be called at 30 bytes but since the writes are chunky flush
|
@@ -370,7 +370,7 @@ class OjWriter < Minitest::Test
|
|
370
370
|
end
|
371
371
|
|
372
372
|
def test_stream_writer_push_null_value_with_key
|
373
|
-
output = StringIO.open(
|
373
|
+
output = StringIO.open('', 'w+')
|
374
374
|
w = Oj::StreamWriter.new(output, :indent => 0)
|
375
375
|
w.push_object()
|
376
376
|
w.push_value(nil, 'nothing')
|
data/test/tests.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
|
+
@oj_dir = File.dirname(File.expand_path(__dir__))
|
6
6
|
%w(lib ext).each do |dir|
|
7
|
-
|
7
|
+
$LOAD_PATH << File.join(@oj_dir, dir)
|
8
8
|
end
|
9
9
|
|
10
10
|
require 'test_compat'
|
@@ -25,9 +25,9 @@ require 'test_integer_range'
|
|
25
25
|
|
26
26
|
at_exit do
|
27
27
|
require 'helper'
|
28
|
-
if '3.1.0' <= RUBY_VERSION &&
|
29
|
-
#Oj::debug_odd("teardown before GC.verify_compaction_references")
|
28
|
+
if '3.1.0' <= RUBY_VERSION && RbConfig::CONFIG['host_os'] !~ /(mingw|mswin)/
|
29
|
+
# Oj::debug_odd("teardown before GC.verify_compaction_references")
|
30
30
|
verify_gc_compaction
|
31
|
-
#Oj::debug_odd("teardown after GC.verify_compaction_references")
|
31
|
+
# Oj::debug_odd("teardown after GC.verify_compaction_references")
|
32
32
|
end
|
33
33
|
end
|
data/test/tests_mimic.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
|
+
$LOAD_PATH << File.join(__dir__, 'json_gem')
|
6
6
|
|
7
7
|
require 'json_common_interface_test'
|
8
8
|
require 'json_encoding_test'
|
@@ -15,9 +15,9 @@ require 'json_string_matching_test'
|
|
15
15
|
|
16
16
|
at_exit do
|
17
17
|
require 'helper'
|
18
|
-
if '3.1.0' <= RUBY_VERSION &&
|
19
|
-
#Oj::debug_odd("teardown before GC.verify_compaction_references")
|
18
|
+
if '3.1.0' <= RUBY_VERSION && RbConfig::CONFIG['host_os'] !~ /(mingw|mswin)/
|
19
|
+
# Oj::debug_odd("teardown before GC.verify_compaction_references")
|
20
20
|
verify_gc_compaction
|
21
|
-
#Oj::debug_odd("teardown after GC.verify_compaction_references")
|
21
|
+
# Oj::debug_odd("teardown after GC.verify_compaction_references")
|
22
22
|
end
|
23
23
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
|
+
$LOAD_PATH << File.join(__dir__, 'json_gem')
|
6
6
|
|
7
7
|
require 'json_addition_test'
|
8
8
|
|
9
9
|
at_exit do
|
10
10
|
require 'helper'
|
11
|
-
if '3.1.0' <= RUBY_VERSION &&
|
12
|
-
#Oj::debug_odd("teardown before GC.verify_compaction_references")
|
11
|
+
if '3.1.0' <= RUBY_VERSION && RbConfig::CONFIG['host_os'] !~ /(mingw|mswin)/
|
12
|
+
# Oj::debug_odd("teardown before GC.verify_compaction_references")
|
13
13
|
verify_gc_compaction
|
14
|
-
#Oj::debug_odd("teardown after GC.verify_compaction_references")
|
14
|
+
# Oj::debug_odd("teardown after GC.verify_compaction_references")
|
15
15
|
end
|
16
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.
|
4
|
+
version: 3.15.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: 2023-
|
11
|
+
date: 2023-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -188,9 +188,6 @@ files:
|
|
188
188
|
- test/activesupport7/encoding_test.rb
|
189
189
|
- test/activesupport7/encoding_test_cases.rb
|
190
190
|
- test/activesupport7/time_zone_test_helpers.rb
|
191
|
-
- test/bar.rb
|
192
|
-
- test/baz.rb
|
193
|
-
- test/bug.rb
|
194
191
|
- test/files.rb
|
195
192
|
- test/foo.rb
|
196
193
|
- test/helper.rb
|
@@ -267,7 +264,6 @@ files:
|
|
267
264
|
- test/tests.rb
|
268
265
|
- test/tests_mimic.rb
|
269
266
|
- test/tests_mimic_addition.rb
|
270
|
-
- test/zoo.rb
|
271
267
|
homepage: http://www.ohler.com/oj
|
272
268
|
licenses:
|
273
269
|
- MIT
|
@@ -278,6 +274,7 @@ metadata:
|
|
278
274
|
homepage_uri: http://www.ohler.com/oj/
|
279
275
|
source_code_uri: https://github.com/ohler55/oj
|
280
276
|
wiki_uri: https://github.com/ohler55/oj/wiki
|
277
|
+
rubygems_mfa_required: 'true'
|
281
278
|
post_install_message:
|
282
279
|
rdoc_options:
|
283
280
|
- "--title"
|
data/test/bar.rb
DELETED
data/test/baz.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$: << File.dirname(__FILE__)
|
4
|
-
$oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
5
|
-
%w(lib ext).each do |dir|
|
6
|
-
$: << File.join($oj_dir, dir)
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'oj'
|
10
|
-
Oj.mimic_JSON()
|
11
|
-
|
12
|
-
begin
|
13
|
-
::JSON.load('name=&email=&subject=&comment=&submit=Send+Message')
|
14
|
-
rescue ::JSON::ParserError
|
15
|
-
puts "*** Pass"
|
16
|
-
end
|
data/test/bug.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
$: << '.'
|
2
|
-
$: << File.join(File.dirname(__FILE__), "../lib")
|
3
|
-
$: << File.join(File.dirname(__FILE__), "../ext")
|
4
|
-
|
5
|
-
|
6
|
-
#require 'bundler/setup'
|
7
|
-
require 'oj'
|
8
|
-
require 'active_support'
|
9
|
-
require 'active_support/time_with_zone'
|
10
|
-
require 'tzinfo'
|
11
|
-
|
12
|
-
puts ActiveSupport::TimeWithZone
|
13
|
-
|
14
|
-
json = File.read('./bug.json')
|
15
|
-
|
16
|
-
Oj.load(json)
|