oj 3.14.2 → 3.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +0 -1
- data/ext/oj/buf.h +2 -2
- data/ext/oj/cache.c +16 -16
- data/ext/oj/cache8.c +7 -7
- data/ext/oj/circarray.c +2 -1
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +2 -2
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +6 -14
- data/ext/oj/custom.c +1 -1
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +16 -16
- data/ext/oj/dump_compat.c +551 -576
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +35 -36
- data/ext/oj/dump_strict.c +2 -4
- data/ext/oj/encoder.c +1 -1
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +9 -12
- data/ext/oj/extconf.rb +1 -1
- data/ext/oj/fast.c +24 -38
- data/ext/oj/intern.c +38 -42
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +211 -217
- data/ext/oj/mem.h +10 -10
- data/ext/oj/mimic_json.c +18 -24
- data/ext/oj/object.c +5 -5
- data/ext/oj/odd.c +2 -1
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +60 -81
- data/ext/oj/oj.h +53 -54
- data/ext/oj/parse.c +55 -118
- data/ext/oj/parse.h +5 -10
- data/ext/oj/parser.c +7 -8
- data/ext/oj/parser.h +7 -8
- data/ext/oj/rails.c +28 -59
- data/ext/oj/reader.c +5 -9
- data/ext/oj/reader.h +1 -1
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +1 -1
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +4 -4
- data/ext/oj/saj2.c +32 -49
- data/ext/oj/saj2.h +1 -1
- data/ext/oj/scp.c +3 -14
- data/ext/oj/sparse.c +18 -67
- data/ext/oj/stream_writer.c +5 -18
- data/ext/oj/strict.c +7 -13
- data/ext/oj/string_writer.c +6 -14
- data/ext/oj/trace.h +27 -16
- data/ext/oj/usual.c +62 -61
- data/ext/oj/usual.h +6 -6
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.h +4 -4
- data/ext/oj/wab.c +7 -9
- data/lib/oj/active_support_helper.rb +0 -1
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +0 -1
- data/lib/oj/json.rb +4 -2
- data/lib/oj/mimic.rb +4 -2
- data/lib/oj/state.rb +8 -5
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +0 -1
- data/test/_test_active.rb +0 -1
- data/test/_test_active_mimic.rb +0 -1
- data/test/_test_mimic_rails.rb +0 -1
- data/test/activerecord/result_test.rb +5 -6
- data/test/bar.rb +3 -3
- data/test/files.rb +1 -1
- data/test/foo.rb +5 -48
- data/test/helper.rb +1 -4
- data/test/isolated/shared.rb +3 -2
- data/test/json_gem/json_addition_test.rb +2 -2
- data/test/json_gem/json_common_interface_test.rb +4 -4
- data/test/json_gem/json_encoding_test.rb +0 -0
- data/test/json_gem/json_ext_parser_test.rb +1 -0
- data/test/json_gem/json_fixtures_test.rb +3 -2
- data/test/json_gem/json_generator_test.rb +43 -32
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +46 -46
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/mem.rb +7 -7
- data/test/perf.rb +2 -2
- data/test/perf_compat.rb +1 -1
- data/test/perf_fast.rb +1 -1
- data/test/perf_file.rb +2 -2
- data/test/perf_object.rb +1 -2
- data/test/perf_once.rb +4 -4
- data/test/perf_parser.rb +1 -2
- data/test/perf_saj.rb +1 -2
- data/test/perf_scp.rb +1 -1
- data/test/perf_simple.rb +3 -3
- data/test/perf_strict.rb +1 -1
- data/test/perf_wab.rb +1 -1
- data/test/sample/change.rb +0 -1
- data/test/sample/dir.rb +0 -1
- data/test/sample/doc.rb +0 -1
- data/test/sample/file.rb +0 -1
- data/test/sample/group.rb +0 -1
- data/test/sample/hasprops.rb +0 -1
- data/test/sample/layer.rb +0 -1
- data/test/sample/rect.rb +0 -1
- data/test/sample/shape.rb +0 -1
- data/test/sample/text.rb +0 -1
- data/test/sample.rb +2 -3
- data/test/sample_json.rb +0 -1
- data/test/test_compat.rb +11 -9
- data/test/test_custom.rb +5 -9
- data/test/test_debian.rb +1 -1
- data/test/test_fast.rb +10 -20
- data/test/test_file.rb +8 -8
- data/test/test_integer_range.rb +2 -2
- data/test/test_null.rb +5 -3
- data/test/test_object.rb +6 -5
- data/test/test_parser_saj.rb +23 -21
- data/test/test_parser_usual.rb +3 -3
- data/test/test_saj.rb +2 -0
- data/test/test_scp.rb +6 -6
- data/test/test_strict.rb +6 -4
- data/test/test_various.rb +21 -24
- data/test/test_wab.rb +6 -5
- data/test/test_writer.rb +1 -1
- metadata +17 -26
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/abstract_unit.rb +0 -45
- data/test/activesupport5/decoding_test.rb +0 -133
- data/test/activesupport5/encoding_test.rb +0 -500
- data/test/activesupport5/encoding_test_cases.rb +0 -98
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/activesupport5/time_zone_test_helpers.rb +0 -39
data/test/test_scp.rb
CHANGED
@@ -47,6 +47,7 @@ class AllHandler < Oj::ScHandler
|
|
47
47
|
@calls << [:hash_key, key]
|
48
48
|
return 'too' if 'two' == key
|
49
49
|
return :symbol if 'symbol' == key
|
50
|
+
|
50
51
|
key
|
51
52
|
end
|
52
53
|
|
@@ -346,12 +347,10 @@ class ScpTest < Minitest::Test
|
|
346
347
|
end
|
347
348
|
|
348
349
|
def test_bad_bignum
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
Oj.sc_parse(handler, json)
|
354
|
-
end
|
350
|
+
handler = AllHandler.new()
|
351
|
+
json = %|{"big":-e123456789}|
|
352
|
+
assert_raises Exception do # Can be either Oj::ParseError or ArgumentError depending on Ruby version
|
353
|
+
Oj.sc_parse(handler, json)
|
355
354
|
end
|
356
355
|
end
|
357
356
|
|
@@ -402,6 +401,7 @@ class ScpTest < Minitest::Test
|
|
402
401
|
c.puts json[0..11]
|
403
402
|
10.times {
|
404
403
|
break if c.closed?
|
404
|
+
|
405
405
|
sleep(0.1)
|
406
406
|
}
|
407
407
|
unless c.closed?
|
data/test/test_strict.rb
CHANGED
@@ -152,7 +152,7 @@ class StrictJuice < Minitest::Test
|
|
152
152
|
end
|
153
153
|
|
154
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)
|
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
156
|
end
|
157
157
|
|
158
158
|
def test_deep_nest
|
@@ -160,7 +160,7 @@ class StrictJuice < Minitest::Test
|
|
160
160
|
|
161
161
|
begin
|
162
162
|
n = 10000
|
163
|
-
Oj.strict_load('[' * n + ']' * n)
|
163
|
+
Oj.strict_load(('[' * n) + (']' * n))
|
164
164
|
rescue Exception => e
|
165
165
|
assert(false, e.message)
|
166
166
|
end
|
@@ -266,12 +266,14 @@ class StrictJuice < Minitest::Test
|
|
266
266
|
|
267
267
|
def test_io_file
|
268
268
|
filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
|
269
|
-
File.open(filename, 'w') { |f|
|
269
|
+
File.open(filename, 'w') { |f|
|
270
|
+
f.write(%{{
|
270
271
|
"x":true,
|
271
272
|
"y":58,
|
272
273
|
"z": [1,2,3]
|
273
274
|
}
|
274
|
-
})
|
275
|
+
})
|
276
|
+
}
|
275
277
|
f = File.new(filename)
|
276
278
|
obj = Oj.strict_load(f)
|
277
279
|
f.close()
|
data/test/test_various.rb
CHANGED
@@ -36,7 +36,7 @@ class Juice < Minitest::Test
|
|
36
36
|
super
|
37
37
|
end
|
38
38
|
|
39
|
-
def to_json()
|
39
|
+
def to_json(*_args)
|
40
40
|
%{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
|
41
41
|
end
|
42
42
|
|
@@ -286,7 +286,6 @@ class Juice < Minitest::Test
|
|
286
286
|
--],#
|
287
287
|
--"a"~:*1#
|
288
288
|
}} == json)
|
289
|
-
|
290
289
|
end
|
291
290
|
|
292
291
|
def test_null_char
|
@@ -319,7 +318,7 @@ class Juice < Minitest::Test
|
|
319
318
|
}
|
320
319
|
results = []
|
321
320
|
Oj.load(json, :mode => :strict) { |x, start, len| results << [x, start, len] }
|
322
|
-
assert_equal([[{"a"=>1}, 0, 7], [[1,2], 7, 6], [[3,4], 13, 5], [{"b"=>2}, 18, 8]], results)
|
321
|
+
assert_equal([[{"a"=>1}, 0, 7], [[1, 2], 7, 6], [[3, 4], 13, 5], [{"b"=>2}, 18, 8]], results)
|
323
322
|
end
|
324
323
|
|
325
324
|
def test_multiple_json_no_callback
|
@@ -575,21 +574,21 @@ class Juice < Minitest::Test
|
|
575
574
|
|
576
575
|
IO.pipe do |r, w|
|
577
576
|
if fork
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
577
|
+
r.close
|
578
|
+
#w.nonblock = false
|
579
|
+
a = []
|
580
|
+
10_000.times do |i|
|
581
|
+
a << i
|
582
|
+
end
|
583
|
+
Oj.to_stream(w, a, indent: 2)
|
584
|
+
w.close
|
586
585
|
else
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
586
|
+
w.close
|
587
|
+
sleep(0.1) # to force a busy
|
588
|
+
cnt = 0
|
589
|
+
r.each_line { cnt += 1 }
|
590
|
+
r.close
|
591
|
+
Process.exit(0)
|
593
592
|
end
|
594
593
|
end
|
595
594
|
end
|
@@ -693,24 +692,22 @@ class Juice < Minitest::Test
|
|
693
692
|
msg = ''
|
694
693
|
assert_raises(Oj::ParseError) {
|
695
694
|
begin
|
696
|
-
|
695
|
+
Oj.load(%|{
|
697
696
|
"first": [
|
698
697
|
1, 2, { "third": 123x }
|
699
698
|
]
|
700
699
|
}|)
|
701
700
|
rescue Oj::ParseError => e
|
702
|
-
|
703
|
-
|
701
|
+
msg = e.message
|
702
|
+
raise e
|
704
703
|
end
|
705
704
|
}
|
706
705
|
assert_equal('after first[2].third', msg.split('(')[1].split(')')[0])
|
707
706
|
end
|
708
707
|
|
709
708
|
def test_bad_bignum
|
710
|
-
|
711
|
-
|
712
|
-
Oj.load(%|{ "big": -e123456789 }|, mode: :strict)
|
713
|
-
end
|
709
|
+
assert_raises Oj::ParseError do
|
710
|
+
Oj.load(%|{ "big": -e123456789 }|, mode: :strict)
|
714
711
|
end
|
715
712
|
end
|
716
713
|
|
data/test/test_wab.rb
CHANGED
@@ -32,7 +32,6 @@ module WAB
|
|
32
32
|
end # UUID
|
33
33
|
end # WAB
|
34
34
|
|
35
|
-
|
36
35
|
class WabJuice < Minitest::Test
|
37
36
|
|
38
37
|
module TestModule
|
@@ -101,7 +100,7 @@ class WabJuice < Minitest::Test
|
|
101
100
|
end
|
102
101
|
|
103
102
|
def test_array_deep
|
104
|
-
dump_and_load([1,[2,[3,[4,[5,[6,[7,[8,[9,[10,[11,[12,[13,[14,[15,[16,[17,[18,[19,[20]]]]]]]]]]]]]]]]]]]], false)
|
103
|
+
dump_and_load([1, [2, [3, [4, [5, [6, [7, [8, [9, [10, [11, [12, [13, [14, [15, [16, [17, [18, [19, [20]]]]]]]]]]]]]]]]]]]], false)
|
105
104
|
end
|
106
105
|
|
107
106
|
def test_deep_nest
|
@@ -109,7 +108,7 @@ class WabJuice < Minitest::Test
|
|
109
108
|
|
110
109
|
begin
|
111
110
|
n = 10000
|
112
|
-
Oj.wab_load('[' * n + ']' * n)
|
111
|
+
Oj.wab_load(('[' * n) + (']' * n))
|
113
112
|
rescue Exception => e
|
114
113
|
assert(false, e.message)
|
115
114
|
end
|
@@ -189,12 +188,14 @@ class WabJuice < Minitest::Test
|
|
189
188
|
|
190
189
|
def test_io_file
|
191
190
|
filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
|
192
|
-
File.open(filename, 'w') { |f|
|
191
|
+
File.open(filename, 'w') { |f|
|
192
|
+
f.write(%{{
|
193
193
|
"x":true,
|
194
194
|
"y":58,
|
195
195
|
"z": [1,2,3]
|
196
196
|
}
|
197
|
-
})
|
197
|
+
})
|
198
|
+
}
|
198
199
|
f = File.new(filename)
|
199
200
|
obj = Oj.wab_load(f)
|
200
201
|
f.close()
|
data/test/test_writer.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.14.
|
4
|
+
version: 3.14.3
|
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-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake-compiler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,20 +44,6 @@ dependencies:
|
|
30
44
|
- - "<"
|
31
45
|
- !ruby/object:Gem::Version
|
32
46
|
version: '2.0'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: minitest
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '5'
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '5'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: test-unit
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,15 +176,6 @@ files:
|
|
176
176
|
- test/_test_active_mimic.rb
|
177
177
|
- test/_test_mimic_rails.rb
|
178
178
|
- test/activerecord/result_test.rb
|
179
|
-
- test/activesupport4/decoding_test.rb
|
180
|
-
- test/activesupport4/encoding_test.rb
|
181
|
-
- test/activesupport4/test_helper.rb
|
182
|
-
- test/activesupport5/abstract_unit.rb
|
183
|
-
- test/activesupport5/decoding_test.rb
|
184
|
-
- test/activesupport5/encoding_test.rb
|
185
|
-
- test/activesupport5/encoding_test_cases.rb
|
186
|
-
- test/activesupport5/test_helper.rb
|
187
|
-
- test/activesupport5/time_zone_test_helpers.rb
|
188
179
|
- test/activesupport6/abstract_unit.rb
|
189
180
|
- test/activesupport6/decoding_test.rb
|
190
181
|
- test/activesupport6/encoding_test.rb
|
@@ -299,7 +290,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
299
290
|
requirements:
|
300
291
|
- - ">="
|
301
292
|
- !ruby/object:Gem::Version
|
302
|
-
version: '2.
|
293
|
+
version: '2.7'
|
303
294
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
304
295
|
requirements:
|
305
296
|
- - ">="
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'activesupport4/test_helper'
|
3
|
-
require 'active_support/json'
|
4
|
-
require 'active_support/time'
|
5
|
-
|
6
|
-
class TestJSONDecoding < ActiveSupport::TestCase
|
7
|
-
class Foo
|
8
|
-
def self.json_create(object)
|
9
|
-
"Foo"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
TESTS = {
|
14
|
-
%q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}},
|
15
|
-
%q({"return\\"To\\":":{"\/categories":"\/"}}) => {"return\"To\":" => {"/categories" => "/"}},
|
16
|
-
%q({"returnTo":{"\/categories":1}}) => {"returnTo" => {"/categories" => 1}},
|
17
|
-
%({"returnTo":[1,"a"]}) => {"returnTo" => [1, "a"]},
|
18
|
-
%({"returnTo":[1,"\\"a\\",", "b"]}) => {"returnTo" => [1, "\"a\",", "b"]},
|
19
|
-
%({"a": "'", "b": "5,000"}) => {"a" => "'", "b" => "5,000"},
|
20
|
-
%({"a": "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"},
|
21
|
-
# multibyte
|
22
|
-
%({"matzue": "松江", "asakusa": "浅草"}) => {"matzue" => "松江", "asakusa" => "浅草"},
|
23
|
-
%({"a": "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)},
|
24
|
-
%({"a": "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)},
|
25
|
-
%(["2007-01-01 01:12:34 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34)],
|
26
|
-
%(["2007-01-01 01:12:34 Z", "2007-01-01 01:12:35 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34), Time.utc(2007, 1, 1, 1, 12, 35)],
|
27
|
-
# no time zone
|
28
|
-
%({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"},
|
29
|
-
# invalid date
|
30
|
-
%({"a": "1089-10-40"}) => {'a' => "1089-10-40"},
|
31
|
-
# xmlschema date notation
|
32
|
-
%({"a": "2009-08-10T19:01:02Z"}) => {'a' => Time.utc(2009, 8, 10, 19, 1, 2)},
|
33
|
-
%({"a": "2009-08-10T19:01:02+02:00"}) => {'a' => Time.utc(2009, 8, 10, 17, 1, 2)},
|
34
|
-
%({"a": "2009-08-10T19:01:02-05:00"}) => {'a' => Time.utc(2009, 8, 11, 00, 1, 2)},
|
35
|
-
# needs to be *exact*
|
36
|
-
%({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "},
|
37
|
-
%({"a": "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"},
|
38
|
-
%([]) => [],
|
39
|
-
%({}) => {},
|
40
|
-
%({"a":1}) => {"a" => 1},
|
41
|
-
%({"a": ""}) => {"a" => ""},
|
42
|
-
%({"a":"\\""}) => {"a" => "\""},
|
43
|
-
%({"a": null}) => {"a" => nil},
|
44
|
-
%({"a": true}) => {"a" => true},
|
45
|
-
%({"a": false}) => {"a" => false},
|
46
|
-
%q({"bad":"\\\\","trailing":""}) => {"bad" => "\\", "trailing" => ""},
|
47
|
-
%q({"a": "http:\/\/test.host\/posts\/1"}) => {"a" => "http://test.host/posts/1"},
|
48
|
-
%q({"a": "\u003cunicode\u0020escape\u003e"}) => {"a" => "<unicode escape>"},
|
49
|
-
%q({"a": "\\\\u0020skip double backslashes"}) => {"a" => "\\u0020skip double backslashes"},
|
50
|
-
%q({"a": "\u003cbr /\u003e"}) => {'a' => "<br />"},
|
51
|
-
%q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]},
|
52
|
-
# test combination of dates and escaped or unicode encoded data in arrays
|
53
|
-
%q([{"d":"1970-01-01", "s":"\u0020escape"},{"d":"1970-01-01", "s":"\u0020escape"}]) =>
|
54
|
-
[{'d' => Date.new(1970, 1, 1), 's' => ' escape'},{'d' => Date.new(1970, 1, 1), 's' => ' escape'}],
|
55
|
-
%q([{"d":"1970-01-01","s":"http:\/\/example.com"},{"d":"1970-01-01","s":"http:\/\/example.com"}]) =>
|
56
|
-
[{'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'},
|
57
|
-
{'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}],
|
58
|
-
# tests escaping of "\n" char with Yaml backend
|
59
|
-
%q({"a":"\n"}) => {"a"=>"\n"},
|
60
|
-
%q({"a":"\u000a"}) => {"a"=>"\n"},
|
61
|
-
%q({"a":"Line1\u000aLine2"}) => {"a"=>"Line1\nLine2"},
|
62
|
-
# prevent json unmarshalling
|
63
|
-
%q({"json_class":"TestJSONDecoding::Foo"}) => {"json_class"=>"TestJSONDecoding::Foo"},
|
64
|
-
# json "fragments" - these are invalid JSON, but ActionPack relies on this
|
65
|
-
%q("a string") => "a string",
|
66
|
-
%q(1.1) => 1.1,
|
67
|
-
%q(1) => 1,
|
68
|
-
%q(-1) => -1,
|
69
|
-
%q(true) => true,
|
70
|
-
%q(false) => false,
|
71
|
-
%q(null) => nil
|
72
|
-
}
|
73
|
-
|
74
|
-
TESTS.each_with_index do |(json, expected), index|
|
75
|
-
test "json decodes #{index}" do
|
76
|
-
prev = ActiveSupport.parse_json_times
|
77
|
-
ActiveSupport.parse_json_times = true
|
78
|
-
silence_warnings do
|
79
|
-
if expected.nil?
|
80
|
-
assert_nil ActiveSupport::JSON.decode(json), "JSON decoding failed for #{json}"
|
81
|
-
else
|
82
|
-
assert_equal expected, ActiveSupport::JSON.decode(json), "JSON decoding failed for #{json}"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
ActiveSupport.parse_json_times = prev
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
test "json decodes time json with time parsing disabled" do
|
90
|
-
prev = ActiveSupport.parse_json_times
|
91
|
-
ActiveSupport.parse_json_times = false
|
92
|
-
expected = {"a" => "2007-01-01 01:12:34 Z"}
|
93
|
-
assert_equal expected, ActiveSupport::JSON.decode(%({"a": "2007-01-01 01:12:34 Z"}))
|
94
|
-
ActiveSupport.parse_json_times = prev
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_failed_json_decoding
|
98
|
-
assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%(undefined)) }
|
99
|
-
assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%({a: 1})) }
|
100
|
-
assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%({: 1})) }
|
101
|
-
assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%()) }
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_cannot_pass_unsupported_options
|
105
|
-
assert_raise(ArgumentError) { ActiveSupport::JSON.decode("", create_additions: true) }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|