oj 3.13.12 → 3.13.15
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/ext/oj/dump.c +22 -13
- data/ext/oj/dump_compat.c +0 -5
- data/ext/oj/dump_object.c +2 -57
- data/ext/oj/extconf.rb +5 -4
- data/ext/oj/mimic_json.c +19 -9
- data/ext/oj/oj.c +17 -3
- data/ext/oj/oj.h +1 -1
- data/ext/oj/parse.c +50 -15
- data/ext/oj/rails.c +0 -5
- data/ext/oj/sparse.c +4 -0
- data/ext/oj/wab.c +0 -5
- data/lib/oj/version.rb +1 -1
- data/test/activesupport7/abstract_unit.rb +49 -0
- data/test/activesupport7/decoding_test.rb +125 -0
- data/test/activesupport7/encoding_test.rb +486 -0
- data/test/activesupport7/encoding_test_cases.rb +104 -0
- data/test/activesupport7/time_zone_test_helpers.rb +47 -0
- data/test/bar.rb +8 -1
- data/test/json_gem/json_generator_test.rb +2 -0
- data/test/json_gem/json_parser_test.rb +7 -0
- data/test/test_compat.rb +16 -0
- data/test/test_file.rb +18 -0
- data/test/test_various.rb +6 -0
- metadata +8 -116
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bigdecimal"
|
4
|
+
require "date"
|
5
|
+
require "time"
|
6
|
+
require "pathname"
|
7
|
+
require "uri"
|
8
|
+
|
9
|
+
module JSONTest
|
10
|
+
class Foo
|
11
|
+
def initialize(a, b)
|
12
|
+
@a, @b = a, b
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Hashlike
|
17
|
+
def to_hash
|
18
|
+
{ foo: "hello", bar: "world" }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Custom
|
23
|
+
def initialize(serialized)
|
24
|
+
@serialized = serialized
|
25
|
+
end
|
26
|
+
|
27
|
+
def as_json(options = nil)
|
28
|
+
@serialized
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
MyStruct = Struct.new(:name, :value) do
|
33
|
+
def initialize(*)
|
34
|
+
@unused = "unused instance variable"
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module EncodingTestCases
|
40
|
+
TrueTests = [[ true, %(true) ]]
|
41
|
+
FalseTests = [[ false, %(false) ]]
|
42
|
+
NilTests = [[ nil, %(null) ]]
|
43
|
+
NumericTests = [[ 1, %(1) ],
|
44
|
+
[ 2.5, %(2.5) ],
|
45
|
+
[ 0.0 / 0.0, %(null) ],
|
46
|
+
[ 1.0 / 0.0, %(null) ],
|
47
|
+
[ -1.0 / 0.0, %(null) ],
|
48
|
+
[ BigDecimal("0.0") / BigDecimal("0.0"), %(null) ],
|
49
|
+
[ BigDecimal("2.5"), %("#{BigDecimal('2.5')}") ]]
|
50
|
+
|
51
|
+
StringTests = [[ "this is the <string>", %("this is the \\u003cstring\\u003e")],
|
52
|
+
[ 'a "string" with quotes & an ampersand', %("a \\"string\\" with quotes \\u0026 an ampersand") ],
|
53
|
+
[ "http://test.host/posts/1", %("http://test.host/posts/1")],
|
54
|
+
[ "Control characters: \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\u2028\u2029",
|
55
|
+
%("Control characters: \\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f\\u2028\\u2029") ]]
|
56
|
+
|
57
|
+
ArrayTests = [[ ["a", "b", "c"], %([\"a\",\"b\",\"c\"]) ],
|
58
|
+
[ [1, "a", :b, nil, false], %([1,\"a\",\"b\",null,false]) ]]
|
59
|
+
|
60
|
+
HashTests = [[ { foo: "bar" }, %({\"foo\":\"bar\"}) ],
|
61
|
+
[ { 1 => 1, 2 => "a", 3 => :b, 4 => nil, 5 => false }, %({\"1\":1,\"2\":\"a\",\"3\":\"b\",\"4\":null,\"5\":false}) ]]
|
62
|
+
|
63
|
+
RangeTests = [[ 1..2, %("1..2")],
|
64
|
+
[ 1...2, %("1...2")],
|
65
|
+
[ 1.5..2.5, %("1.5..2.5")]]
|
66
|
+
|
67
|
+
SymbolTests = [[ :a, %("a") ],
|
68
|
+
[ :this, %("this") ],
|
69
|
+
[ :"a b", %("a b") ]]
|
70
|
+
|
71
|
+
ModuleTests = [[ Module, %("Module") ],
|
72
|
+
[ Class, %("Class") ],
|
73
|
+
[ ActiveSupport, %("ActiveSupport") ],
|
74
|
+
[ ActiveSupport::MessageEncryptor, %("ActiveSupport::MessageEncryptor") ]]
|
75
|
+
ObjectTests = [[ Foo.new(1, 2), %({\"a\":1,\"b\":2}) ]]
|
76
|
+
HashlikeTests = [[ Hashlike.new, %({\"bar\":\"world\",\"foo\":\"hello\"}) ]]
|
77
|
+
StructTests = [[ MyStruct.new(:foo, "bar"), %({\"name\":\"foo\",\"value\":\"bar\"}) ],
|
78
|
+
[ MyStruct.new(nil, nil), %({\"name\":null,\"value\":null}) ]]
|
79
|
+
CustomTests = [[ Custom.new("custom"), '"custom"' ],
|
80
|
+
[ Custom.new(nil), "null" ],
|
81
|
+
[ Custom.new(:a), '"a"' ],
|
82
|
+
[ Custom.new([ :foo, "bar" ]), '["foo","bar"]' ],
|
83
|
+
[ Custom.new(foo: "hello", bar: "world"), '{"bar":"world","foo":"hello"}' ],
|
84
|
+
[ Custom.new(Hashlike.new), '{"bar":"world","foo":"hello"}' ],
|
85
|
+
[ Custom.new(Custom.new(Custom.new(:a))), '"a"' ]]
|
86
|
+
|
87
|
+
RegexpTests = [[ /^a/, '"(?-mix:^a)"' ], [/^\w{1,2}[a-z]+/ix, '"(?ix-m:^\\\\w{1,2}[a-z]+)"']]
|
88
|
+
|
89
|
+
URITests = [[ URI.parse("http://example.com"), %("http://example.com") ]]
|
90
|
+
|
91
|
+
PathnameTests = [[ Pathname.new("lib/index.rb"), %("lib/index.rb") ]]
|
92
|
+
|
93
|
+
IPAddrTests = [[ IPAddr.new("127.0.0.1"), %("127.0.0.1") ]]
|
94
|
+
|
95
|
+
DateTests = [[ Date.new(2005, 2, 1), %("2005/02/01") ]]
|
96
|
+
TimeTests = [[ Time.utc(2005, 2, 1, 15, 15, 10), %("2005/02/01 15:15:10 +0000") ]]
|
97
|
+
DateTimeTests = [[ DateTime.civil(2005, 2, 1, 15, 15, 10), %("2005/02/01 15:15:10 +0000") ]]
|
98
|
+
|
99
|
+
StandardDateTests = [[ Date.new(2005, 2, 1), %("2005-02-01") ]]
|
100
|
+
StandardTimeTests = [[ Time.utc(2005, 2, 1, 15, 15, 10), %("2005-02-01T15:15:10.000Z") ]]
|
101
|
+
StandardDateTimeTests = [[ DateTime.civil(2005, 2, 1, 15, 15, 10), %("2005-02-01T15:15:10.000+00:00") ]]
|
102
|
+
StandardStringTests = [[ "this is the <string>", %("this is the <string>")]]
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TimeZoneTestHelpers
|
4
|
+
def with_tz_default(tz = nil)
|
5
|
+
old_tz = Time.zone
|
6
|
+
Time.zone = tz
|
7
|
+
yield
|
8
|
+
ensure
|
9
|
+
Time.zone = old_tz
|
10
|
+
end
|
11
|
+
|
12
|
+
def with_env_tz(new_tz = "US/Eastern")
|
13
|
+
old_tz, ENV["TZ"] = ENV["TZ"], new_tz
|
14
|
+
yield
|
15
|
+
ensure
|
16
|
+
old_tz ? ENV["TZ"] = old_tz : ENV.delete("TZ")
|
17
|
+
end
|
18
|
+
|
19
|
+
def with_preserve_timezone(value)
|
20
|
+
old_preserve_tz = ActiveSupport.to_time_preserves_timezone
|
21
|
+
ActiveSupport.to_time_preserves_timezone = value
|
22
|
+
yield
|
23
|
+
ensure
|
24
|
+
ActiveSupport.to_time_preserves_timezone = old_preserve_tz
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_tz_mappings(mappings)
|
28
|
+
old_mappings = ActiveSupport::TimeZone::MAPPING.dup
|
29
|
+
ActiveSupport::TimeZone.clear
|
30
|
+
ActiveSupport::TimeZone::MAPPING.clear
|
31
|
+
ActiveSupport::TimeZone::MAPPING.merge!(mappings)
|
32
|
+
|
33
|
+
yield
|
34
|
+
ensure
|
35
|
+
ActiveSupport::TimeZone.clear
|
36
|
+
ActiveSupport::TimeZone::MAPPING.clear
|
37
|
+
ActiveSupport::TimeZone::MAPPING.merge!(old_mappings)
|
38
|
+
end
|
39
|
+
|
40
|
+
def with_utc_to_local_returns_utc_offset_times(value)
|
41
|
+
old_tzinfo2_format = ActiveSupport.utc_to_local_returns_utc_offset_times
|
42
|
+
ActiveSupport.utc_to_local_returns_utc_offset_times = value
|
43
|
+
yield
|
44
|
+
ensure
|
45
|
+
ActiveSupport.utc_to_local_returns_utc_offset_times = old_tzinfo2_format
|
46
|
+
end
|
47
|
+
end
|
data/test/bar.rb
CHANGED
@@ -6,4 +6,11 @@ $: << File.join(File.dirname(__FILE__), "../ext")
|
|
6
6
|
|
7
7
|
require 'oj'
|
8
8
|
|
9
|
-
Oj.
|
9
|
+
puts Oj.dump({
|
10
|
+
"float_test" => 0.25,
|
11
|
+
"nan_test" => Float::NAN,
|
12
|
+
"inf_test" => Float::INFINITY,
|
13
|
+
"minus_inf_test" => -Float::INFINITY,
|
14
|
+
"min_test" => Float::MIN,
|
15
|
+
"max_test" => Float::MAX,
|
16
|
+
}, mode: :object) # => {"float_test":0.25,"nan_test":3.3e14159265358979323846
|
@@ -269,6 +269,13 @@ EOT
|
|
269
269
|
assert_equal too_deep_ary, ok
|
270
270
|
ok = JSON.parse too_deep, :max_nesting => 0
|
271
271
|
assert_equal too_deep_ary, ok
|
272
|
+
|
273
|
+
unless ENV['REAL_JSON_GEM']
|
274
|
+
# max_nesting should be reset to 0 if not included in options
|
275
|
+
# This behavior is not compatible with Ruby standard JSON gem
|
276
|
+
ok = JSON.parse too_deep, {}
|
277
|
+
assert_equal too_deep_ary, ok
|
278
|
+
end
|
272
279
|
end
|
273
280
|
|
274
281
|
def test_backslash
|
data/test/test_compat.rb
CHANGED
@@ -488,6 +488,22 @@ class CompatJuice < Minitest::Test
|
|
488
488
|
assert_equal([1,2], Oj.load(s, :mode => :compat))
|
489
489
|
end
|
490
490
|
|
491
|
+
def test_parse_large_string
|
492
|
+
error = assert_raises() { Oj.load(%|{"a":"aaaaaaaaaa\0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}|) }
|
493
|
+
assert(error.message.include?('NULL byte in string'))
|
494
|
+
|
495
|
+
error = assert_raises() { Oj.load(%|{"a":"aaaaaaaaaaaaaaaaaaaa }|) }
|
496
|
+
assert(error.message.include?('quoted string not terminated'))
|
497
|
+
|
498
|
+
json =<<~JSON
|
499
|
+
{
|
500
|
+
"a": "\\u3074\\u30fc\\u305f\\u30fc",
|
501
|
+
"b": "aaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
502
|
+
}
|
503
|
+
JSON
|
504
|
+
assert_equal("ぴーたー", Oj.load(json)['a'])
|
505
|
+
end
|
506
|
+
|
491
507
|
def dump_and_load(obj, trace=false)
|
492
508
|
json = Oj.dump(obj)
|
493
509
|
puts json if trace
|
data/test/test_file.rb
CHANGED
@@ -212,6 +212,24 @@ class FileJuice < Minitest::Test
|
|
212
212
|
dump_and_load(DateTime.new(2012, 6, 19), false)
|
213
213
|
end
|
214
214
|
|
215
|
+
def test_load_unicode_path
|
216
|
+
json =<<~JSON
|
217
|
+
{
|
218
|
+
"x":true,
|
219
|
+
"y":58,
|
220
|
+
"z": [1,2,3]
|
221
|
+
}
|
222
|
+
JSON
|
223
|
+
|
224
|
+
Tempfile.create('file_test_conceição1.json') do |f|
|
225
|
+
f.write(json)
|
226
|
+
f.close
|
227
|
+
|
228
|
+
objects = Oj.load_file(f.path)
|
229
|
+
assert_equal(Oj.load(json), objects)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
215
233
|
def dump_and_load(obj, trace=false)
|
216
234
|
filename = File.join(File.dirname(__FILE__), 'file_test.json')
|
217
235
|
File.open(filename, "w") { |f|
|
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)
|
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.
|
4
|
+
version: 3.13.15
|
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-
|
11
|
+
date: 2022-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -58,20 +58,6 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3.0'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: wwtd
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
75
61
|
description: The fastest JSON parser and object serializer.
|
76
62
|
email: peter@ohler.com
|
77
63
|
executables: []
|
@@ -200,6 +186,11 @@ files:
|
|
200
186
|
- test/activesupport6/test_common.rb
|
201
187
|
- test/activesupport6/test_helper.rb
|
202
188
|
- test/activesupport6/time_zone_test_helpers.rb
|
189
|
+
- test/activesupport7/abstract_unit.rb
|
190
|
+
- test/activesupport7/decoding_test.rb
|
191
|
+
- test/activesupport7/encoding_test.rb
|
192
|
+
- test/activesupport7/encoding_test_cases.rb
|
193
|
+
- test/activesupport7/time_zone_test_helpers.rb
|
203
194
|
- test/bar.rb
|
204
195
|
- test/baz.rb
|
205
196
|
- test/bug.rb
|
@@ -312,103 +303,4 @@ rubygems_version: 3.3.3
|
|
312
303
|
signing_key:
|
313
304
|
specification_version: 4
|
314
305
|
summary: A fast JSON parser and serializer.
|
315
|
-
test_files:
|
316
|
-
- test/_test_active.rb
|
317
|
-
- test/_test_active_mimic.rb
|
318
|
-
- test/_test_mimic_rails.rb
|
319
|
-
- test/activerecord/result_test.rb
|
320
|
-
- test/activesupport4/decoding_test.rb
|
321
|
-
- test/activesupport4/encoding_test.rb
|
322
|
-
- test/activesupport4/test_helper.rb
|
323
|
-
- test/activesupport5/abstract_unit.rb
|
324
|
-
- test/activesupport5/decoding_test.rb
|
325
|
-
- test/activesupport5/encoding_test.rb
|
326
|
-
- test/activesupport5/encoding_test_cases.rb
|
327
|
-
- test/activesupport5/test_helper.rb
|
328
|
-
- test/activesupport5/time_zone_test_helpers.rb
|
329
|
-
- test/activesupport6/abstract_unit.rb
|
330
|
-
- test/activesupport6/decoding_test.rb
|
331
|
-
- test/activesupport6/encoding_test.rb
|
332
|
-
- test/activesupport6/encoding_test_cases.rb
|
333
|
-
- test/activesupport6/test_common.rb
|
334
|
-
- test/activesupport6/test_helper.rb
|
335
|
-
- test/activesupport6/time_zone_test_helpers.rb
|
336
|
-
- test/bar.rb
|
337
|
-
- test/baz.rb
|
338
|
-
- test/bug.rb
|
339
|
-
- test/files.rb
|
340
|
-
- test/foo.rb
|
341
|
-
- test/helper.rb
|
342
|
-
- test/isolated/shared.rb
|
343
|
-
- test/isolated/test_mimic_after.rb
|
344
|
-
- test/isolated/test_mimic_alone.rb
|
345
|
-
- test/isolated/test_mimic_as_json.rb
|
346
|
-
- test/isolated/test_mimic_before.rb
|
347
|
-
- test/isolated/test_mimic_define.rb
|
348
|
-
- test/isolated/test_mimic_rails_after.rb
|
349
|
-
- test/isolated/test_mimic_rails_before.rb
|
350
|
-
- test/isolated/test_mimic_redefine.rb
|
351
|
-
- test/json_gem/json_addition_test.rb
|
352
|
-
- test/json_gem/json_common_interface_test.rb
|
353
|
-
- test/json_gem/json_encoding_test.rb
|
354
|
-
- test/json_gem/json_ext_parser_test.rb
|
355
|
-
- test/json_gem/json_fixtures_test.rb
|
356
|
-
- test/json_gem/json_generator_test.rb
|
357
|
-
- test/json_gem/json_generic_object_test.rb
|
358
|
-
- test/json_gem/json_parser_test.rb
|
359
|
-
- test/json_gem/json_string_matching_test.rb
|
360
|
-
- test/json_gem/test_helper.rb
|
361
|
-
- test/mem.rb
|
362
|
-
- test/perf.rb
|
363
|
-
- test/perf_compat.rb
|
364
|
-
- test/perf_dump.rb
|
365
|
-
- test/perf_fast.rb
|
366
|
-
- test/perf_file.rb
|
367
|
-
- test/perf_object.rb
|
368
|
-
- test/perf_once.rb
|
369
|
-
- test/perf_parser.rb
|
370
|
-
- test/perf_saj.rb
|
371
|
-
- test/perf_scp.rb
|
372
|
-
- test/perf_simple.rb
|
373
|
-
- test/perf_strict.rb
|
374
|
-
- test/perf_wab.rb
|
375
|
-
- test/prec.rb
|
376
|
-
- test/sample/change.rb
|
377
|
-
- test/sample/dir.rb
|
378
|
-
- test/sample/doc.rb
|
379
|
-
- test/sample/file.rb
|
380
|
-
- test/sample/group.rb
|
381
|
-
- test/sample/hasprops.rb
|
382
|
-
- test/sample/layer.rb
|
383
|
-
- test/sample/line.rb
|
384
|
-
- test/sample/oval.rb
|
385
|
-
- test/sample/rect.rb
|
386
|
-
- test/sample/shape.rb
|
387
|
-
- test/sample/text.rb
|
388
|
-
- test/sample.rb
|
389
|
-
- test/sample_json.rb
|
390
|
-
- test/test_compat.rb
|
391
|
-
- test/test_custom.rb
|
392
|
-
- test/test_debian.rb
|
393
|
-
- test/test_fast.rb
|
394
|
-
- test/test_file.rb
|
395
|
-
- test/test_gc.rb
|
396
|
-
- test/test_generate.rb
|
397
|
-
- test/test_hash.rb
|
398
|
-
- test/test_integer_range.rb
|
399
|
-
- test/test_null.rb
|
400
|
-
- test/test_object.rb
|
401
|
-
- test/test_parser.rb
|
402
|
-
- test/test_parser_saj.rb
|
403
|
-
- test/test_parser_usual.rb
|
404
|
-
- test/test_rails.rb
|
405
|
-
- test/test_saj.rb
|
406
|
-
- test/test_scp.rb
|
407
|
-
- test/test_strict.rb
|
408
|
-
- test/test_various.rb
|
409
|
-
- test/test_wab.rb
|
410
|
-
- test/test_writer.rb
|
411
|
-
- test/tests.rb
|
412
|
-
- test/tests_mimic.rb
|
413
|
-
- test/tests_mimic_addition.rb
|
414
|
-
- test/zoo.rb
|
306
|
+
test_files: []
|