oj 3.13.11 → 3.15.0

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 (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +74 -0
  3. data/README.md +4 -2
  4. data/ext/oj/buf.h +11 -6
  5. data/ext/oj/cache.c +25 -24
  6. data/ext/oj/cache8.c +10 -9
  7. data/ext/oj/circarray.c +8 -6
  8. data/ext/oj/circarray.h +2 -2
  9. data/ext/oj/code.c +17 -24
  10. data/ext/oj/code.h +2 -2
  11. data/ext/oj/compat.c +17 -44
  12. data/ext/oj/custom.c +70 -141
  13. data/ext/oj/debug.c +3 -9
  14. data/ext/oj/dump.c +128 -118
  15. data/ext/oj/dump.h +12 -8
  16. data/ext/oj/dump_compat.c +564 -641
  17. data/ext/oj/dump_leaf.c +17 -63
  18. data/ext/oj/dump_object.c +70 -199
  19. data/ext/oj/dump_strict.c +22 -46
  20. data/ext/oj/encoder.c +1 -1
  21. data/ext/oj/err.c +2 -13
  22. data/ext/oj/err.h +9 -12
  23. data/ext/oj/extconf.rb +14 -5
  24. data/ext/oj/fast.c +75 -103
  25. data/ext/oj/intern.c +52 -50
  26. data/ext/oj/intern.h +4 -8
  27. data/ext/oj/mem.c +318 -0
  28. data/ext/oj/mem.h +53 -0
  29. data/ext/oj/mimic_json.c +75 -47
  30. data/ext/oj/object.c +49 -66
  31. data/ext/oj/odd.c +89 -67
  32. data/ext/oj/odd.h +15 -15
  33. data/ext/oj/oj.c +140 -99
  34. data/ext/oj/oj.h +80 -51
  35. data/ext/oj/parse.c +162 -184
  36. data/ext/oj/parse.h +7 -10
  37. data/ext/oj/parser.c +89 -34
  38. data/ext/oj/parser.h +18 -7
  39. data/ext/oj/rails.c +82 -146
  40. data/ext/oj/rails.h +1 -1
  41. data/ext/oj/reader.c +11 -12
  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 +20 -31
  47. data/ext/oj/saj2.c +329 -93
  48. data/ext/oj/saj2.h +23 -0
  49. data/ext/oj/scp.c +3 -14
  50. data/ext/oj/sparse.c +26 -70
  51. data/ext/oj/stream_writer.c +12 -22
  52. data/ext/oj/strict.c +20 -52
  53. data/ext/oj/string_writer.c +21 -21
  54. data/ext/oj/trace.h +31 -4
  55. data/ext/oj/usual.c +105 -150
  56. data/ext/oj/usual.h +68 -0
  57. data/ext/oj/util.h +1 -1
  58. data/ext/oj/val_stack.c +1 -1
  59. data/ext/oj/val_stack.h +8 -7
  60. data/ext/oj/validate.c +21 -26
  61. data/ext/oj/wab.c +31 -68
  62. data/lib/oj/active_support_helper.rb +0 -1
  63. data/lib/oj/bag.rb +7 -1
  64. data/lib/oj/easy_hash.rb +4 -5
  65. data/lib/oj/error.rb +0 -1
  66. data/lib/oj/json.rb +4 -2
  67. data/lib/oj/mimic.rb +4 -2
  68. data/lib/oj/saj.rb +20 -6
  69. data/lib/oj/state.rb +9 -6
  70. data/lib/oj/version.rb +1 -2
  71. data/lib/oj.rb +2 -0
  72. data/pages/Compatibility.md +1 -1
  73. data/pages/InstallOptions.md +20 -0
  74. data/pages/Options.md +10 -0
  75. data/test/_test_active.rb +8 -9
  76. data/test/_test_active_mimic.rb +7 -8
  77. data/test/_test_mimic_rails.rb +17 -20
  78. data/test/activerecord/result_test.rb +5 -6
  79. data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
  80. data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
  81. data/test/{activesupport5 → activesupport7}/encoding_test.rb +20 -34
  82. data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
  83. data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
  84. data/test/files.rb +15 -15
  85. data/test/foo.rb +9 -71
  86. data/test/helper.rb +11 -8
  87. data/test/isolated/shared.rb +3 -2
  88. data/test/json_gem/json_addition_test.rb +2 -2
  89. data/test/json_gem/json_common_interface_test.rb +4 -4
  90. data/test/json_gem/json_encoding_test.rb +0 -0
  91. data/test/json_gem/json_ext_parser_test.rb +1 -0
  92. data/test/json_gem/json_fixtures_test.rb +3 -2
  93. data/test/json_gem/json_generator_test.rb +48 -36
  94. data/test/json_gem/json_generic_object_test.rb +11 -11
  95. data/test/json_gem/json_parser_test.rb +54 -47
  96. data/test/json_gem/json_string_matching_test.rb +9 -9
  97. data/test/json_gem/test_helper.rb +7 -3
  98. data/test/mem.rb +13 -12
  99. data/test/perf.rb +21 -26
  100. data/test/perf_compat.rb +31 -33
  101. data/test/perf_dump.rb +50 -0
  102. data/test/perf_fast.rb +80 -82
  103. data/test/perf_file.rb +27 -29
  104. data/test/perf_object.rb +65 -69
  105. data/test/perf_once.rb +12 -11
  106. data/test/perf_parser.rb +42 -48
  107. data/test/perf_saj.rb +46 -54
  108. data/test/perf_scp.rb +57 -69
  109. data/test/perf_simple.rb +41 -39
  110. data/test/perf_strict.rb +68 -70
  111. data/test/perf_wab.rb +67 -69
  112. data/test/prec.rb +3 -3
  113. data/test/sample/change.rb +0 -1
  114. data/test/sample/dir.rb +0 -1
  115. data/test/sample/doc.rb +0 -1
  116. data/test/sample/file.rb +0 -1
  117. data/test/sample/group.rb +0 -1
  118. data/test/sample/hasprops.rb +0 -1
  119. data/test/sample/layer.rb +0 -1
  120. data/test/sample/rect.rb +0 -1
  121. data/test/sample/shape.rb +0 -1
  122. data/test/sample/text.rb +0 -1
  123. data/test/sample.rb +16 -16
  124. data/test/sample_json.rb +8 -8
  125. data/test/test_compat.rb +76 -42
  126. data/test/test_custom.rb +72 -51
  127. data/test/test_debian.rb +7 -10
  128. data/test/test_fast.rb +86 -90
  129. data/test/test_file.rb +41 -30
  130. data/test/test_gc.rb +16 -5
  131. data/test/test_generate.rb +5 -5
  132. data/test/test_hash.rb +4 -4
  133. data/test/test_integer_range.rb +9 -9
  134. data/test/test_null.rb +20 -20
  135. data/test/test_object.rb +85 -96
  136. data/test/test_parser.rb +6 -22
  137. data/test/test_parser_debug.rb +27 -0
  138. data/test/test_parser_saj.rb +115 -23
  139. data/test/test_parser_usual.rb +6 -6
  140. data/test/test_rails.rb +2 -2
  141. data/test/test_saj.rb +10 -8
  142. data/test/test_scp.rb +37 -39
  143. data/test/test_strict.rb +30 -32
  144. data/test/test_various.rb +147 -99
  145. data/test/test_wab.rb +48 -44
  146. data/test/test_writer.rb +47 -47
  147. data/test/tests.rb +13 -4
  148. data/test/tests_mimic.rb +12 -3
  149. data/test/tests_mimic_addition.rb +12 -3
  150. metadata +33 -144
  151. data/test/activesupport4/decoding_test.rb +0 -108
  152. data/test/activesupport4/encoding_test.rb +0 -531
  153. data/test/activesupport4/test_helper.rb +0 -41
  154. data/test/activesupport5/test_helper.rb +0 -72
  155. data/test/bar.rb +0 -16
  156. data/test/baz.rb +0 -16
  157. data/test/bug.rb +0 -16
  158. data/test/zoo.rb +0 -13
metadata CHANGED
@@ -1,35 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.11
4
+ version: 3.15.0
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-01-05 00:00:00.000000000 Z
11
+ date: 2023-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake-compiler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0.9'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '2.0'
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '0.9'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '2.0'
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: minitest
35
15
  requirement: !ruby/object:Gem::Requirement
@@ -45,33 +25,39 @@ dependencies:
45
25
  - !ruby/object:Gem::Version
46
26
  version: '5'
47
27
  - !ruby/object:Gem::Dependency
48
- name: test-unit
28
+ name: rake-compiler
49
29
  requirement: !ruby/object:Gem::Requirement
50
30
  requirements:
51
- - - "~>"
31
+ - - ">="
52
32
  - !ruby/object:Gem::Version
53
- version: '3.0'
33
+ version: '0.9'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.0'
54
37
  type: :development
55
38
  prerelease: false
56
39
  version_requirements: !ruby/object:Gem::Requirement
57
40
  requirements:
58
- - - "~>"
41
+ - - ">="
59
42
  - !ruby/object:Gem::Version
60
- version: '3.0'
43
+ version: '0.9'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
61
47
  - !ruby/object:Gem::Dependency
62
- name: wwtd
48
+ name: test-unit
63
49
  requirement: !ruby/object:Gem::Requirement
64
50
  requirements:
65
51
  - - "~>"
66
52
  - !ruby/object:Gem::Version
67
- version: '0'
53
+ version: '3.0'
68
54
  type: :development
69
55
  prerelease: false
70
56
  version_requirements: !ruby/object:Gem::Requirement
71
57
  requirements:
72
58
  - - "~>"
73
59
  - !ruby/object:Gem::Version
74
- version: '0'
60
+ version: '3.0'
75
61
  description: The fastest JSON parser and object serializer.
76
62
  email: peter@ohler.com
77
63
  executables: []
@@ -86,6 +72,7 @@ extra_rdoc_files:
86
72
  - pages/Compatibility.md
87
73
  - pages/Custom.md
88
74
  - pages/Encoding.md
75
+ - pages/InstallOptions.md
89
76
  - pages/JsonGem.md
90
77
  - pages/Modes.md
91
78
  - pages/Options.md
@@ -124,6 +111,8 @@ files:
124
111
  - ext/oj/fast.c
125
112
  - ext/oj/intern.c
126
113
  - ext/oj/intern.h
114
+ - ext/oj/mem.c
115
+ - ext/oj/mem.h
127
116
  - ext/oj/mimic_json.c
128
117
  - ext/oj/object.c
129
118
  - ext/oj/odd.c
@@ -144,6 +133,7 @@ files:
144
133
  - ext/oj/rxclass.h
145
134
  - ext/oj/saj.c
146
135
  - ext/oj/saj2.c
136
+ - ext/oj/saj2.h
147
137
  - ext/oj/scp.c
148
138
  - ext/oj/sparse.c
149
139
  - ext/oj/stream_writer.c
@@ -152,6 +142,7 @@ files:
152
142
  - ext/oj/trace.c
153
143
  - ext/oj/trace.h
154
144
  - ext/oj/usual.c
145
+ - ext/oj/usual.h
155
146
  - ext/oj/util.c
156
147
  - ext/oj/util.h
157
148
  - ext/oj/val_stack.c
@@ -173,6 +164,7 @@ files:
173
164
  - pages/Compatibility.md
174
165
  - pages/Custom.md
175
166
  - pages/Encoding.md
167
+ - pages/InstallOptions.md
176
168
  - pages/JsonGem.md
177
169
  - pages/Modes.md
178
170
  - pages/Options.md
@@ -184,15 +176,6 @@ files:
184
176
  - test/_test_active_mimic.rb
185
177
  - test/_test_mimic_rails.rb
186
178
  - test/activerecord/result_test.rb
187
- - test/activesupport4/decoding_test.rb
188
- - test/activesupport4/encoding_test.rb
189
- - test/activesupport4/test_helper.rb
190
- - test/activesupport5/abstract_unit.rb
191
- - test/activesupport5/decoding_test.rb
192
- - test/activesupport5/encoding_test.rb
193
- - test/activesupport5/encoding_test_cases.rb
194
- - test/activesupport5/test_helper.rb
195
- - test/activesupport5/time_zone_test_helpers.rb
196
179
  - test/activesupport6/abstract_unit.rb
197
180
  - test/activesupport6/decoding_test.rb
198
181
  - test/activesupport6/encoding_test.rb
@@ -200,9 +183,11 @@ files:
200
183
  - test/activesupport6/test_common.rb
201
184
  - test/activesupport6/test_helper.rb
202
185
  - test/activesupport6/time_zone_test_helpers.rb
203
- - test/bar.rb
204
- - test/baz.rb
205
- - test/bug.rb
186
+ - test/activesupport7/abstract_unit.rb
187
+ - test/activesupport7/decoding_test.rb
188
+ - test/activesupport7/encoding_test.rb
189
+ - test/activesupport7/encoding_test_cases.rb
190
+ - test/activesupport7/time_zone_test_helpers.rb
206
191
  - test/files.rb
207
192
  - test/foo.rb
208
193
  - test/helper.rb
@@ -228,6 +213,7 @@ files:
228
213
  - test/mem.rb
229
214
  - test/perf.rb
230
215
  - test/perf_compat.rb
216
+ - test/perf_dump.rb
231
217
  - test/perf_fast.rb
232
218
  - test/perf_file.rb
233
219
  - test/perf_object.rb
@@ -265,6 +251,7 @@ files:
265
251
  - test/test_null.rb
266
252
  - test/test_object.rb
267
253
  - test/test_parser.rb
254
+ - test/test_parser_debug.rb
268
255
  - test/test_parser_saj.rb
269
256
  - test/test_parser_usual.rb
270
257
  - test/test_rails.rb
@@ -277,7 +264,6 @@ files:
277
264
  - test/tests.rb
278
265
  - test/tests_mimic.rb
279
266
  - test/tests_mimic_addition.rb
280
- - test/zoo.rb
281
267
  homepage: http://www.ohler.com/oj
282
268
  licenses:
283
269
  - MIT
@@ -288,6 +274,7 @@ metadata:
288
274
  homepage_uri: http://www.ohler.com/oj/
289
275
  source_code_uri: https://github.com/ohler55/oj
290
276
  wiki_uri: https://github.com/ohler55/oj/wiki
277
+ rubygems_mfa_required: 'true'
291
278
  post_install_message:
292
279
  rdoc_options:
293
280
  - "--title"
@@ -300,113 +287,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
300
287
  requirements:
301
288
  - - ">="
302
289
  - !ruby/object:Gem::Version
303
- version: '2.4'
290
+ version: '2.7'
304
291
  required_rubygems_version: !ruby/object:Gem::Requirement
305
292
  requirements:
306
293
  - - ">="
307
294
  - !ruby/object:Gem::Version
308
295
  version: '0'
309
296
  requirements: []
310
- rubygems_version: 3.2.22
297
+ rubygems_version: 3.4.1
311
298
  signing_key:
312
299
  specification_version: 4
313
300
  summary: A fast JSON parser and serializer.
314
- test_files:
315
- - test/_test_active.rb
316
- - test/_test_active_mimic.rb
317
- - test/_test_mimic_rails.rb
318
- - test/activerecord/result_test.rb
319
- - test/activesupport4/decoding_test.rb
320
- - test/activesupport4/encoding_test.rb
321
- - test/activesupport4/test_helper.rb
322
- - test/activesupport5/abstract_unit.rb
323
- - test/activesupport5/decoding_test.rb
324
- - test/activesupport5/encoding_test.rb
325
- - test/activesupport5/encoding_test_cases.rb
326
- - test/activesupport5/test_helper.rb
327
- - test/activesupport5/time_zone_test_helpers.rb
328
- - test/activesupport6/abstract_unit.rb
329
- - test/activesupport6/decoding_test.rb
330
- - test/activesupport6/encoding_test.rb
331
- - test/activesupport6/encoding_test_cases.rb
332
- - test/activesupport6/test_common.rb
333
- - test/activesupport6/test_helper.rb
334
- - test/activesupport6/time_zone_test_helpers.rb
335
- - test/bar.rb
336
- - test/baz.rb
337
- - test/bug.rb
338
- - test/files.rb
339
- - test/foo.rb
340
- - test/helper.rb
341
- - test/isolated/shared.rb
342
- - test/isolated/test_mimic_after.rb
343
- - test/isolated/test_mimic_alone.rb
344
- - test/isolated/test_mimic_as_json.rb
345
- - test/isolated/test_mimic_before.rb
346
- - test/isolated/test_mimic_define.rb
347
- - test/isolated/test_mimic_rails_after.rb
348
- - test/isolated/test_mimic_rails_before.rb
349
- - test/isolated/test_mimic_redefine.rb
350
- - test/json_gem/json_addition_test.rb
351
- - test/json_gem/json_common_interface_test.rb
352
- - test/json_gem/json_encoding_test.rb
353
- - test/json_gem/json_ext_parser_test.rb
354
- - test/json_gem/json_fixtures_test.rb
355
- - test/json_gem/json_generator_test.rb
356
- - test/json_gem/json_generic_object_test.rb
357
- - test/json_gem/json_parser_test.rb
358
- - test/json_gem/json_string_matching_test.rb
359
- - test/json_gem/test_helper.rb
360
- - test/mem.rb
361
- - test/perf.rb
362
- - test/perf_compat.rb
363
- - test/perf_fast.rb
364
- - test/perf_file.rb
365
- - test/perf_object.rb
366
- - test/perf_once.rb
367
- - test/perf_parser.rb
368
- - test/perf_saj.rb
369
- - test/perf_scp.rb
370
- - test/perf_simple.rb
371
- - test/perf_strict.rb
372
- - test/perf_wab.rb
373
- - test/prec.rb
374
- - test/sample/change.rb
375
- - test/sample/dir.rb
376
- - test/sample/doc.rb
377
- - test/sample/file.rb
378
- - test/sample/group.rb
379
- - test/sample/hasprops.rb
380
- - test/sample/layer.rb
381
- - test/sample/line.rb
382
- - test/sample/oval.rb
383
- - test/sample/rect.rb
384
- - test/sample/shape.rb
385
- - test/sample/text.rb
386
- - test/sample.rb
387
- - test/sample_json.rb
388
- - test/test_compat.rb
389
- - test/test_custom.rb
390
- - test/test_debian.rb
391
- - test/test_fast.rb
392
- - test/test_file.rb
393
- - test/test_gc.rb
394
- - test/test_generate.rb
395
- - test/test_hash.rb
396
- - test/test_integer_range.rb
397
- - test/test_null.rb
398
- - test/test_object.rb
399
- - test/test_parser.rb
400
- - test/test_parser_saj.rb
401
- - test/test_parser_usual.rb
402
- - test/test_rails.rb
403
- - test/test_saj.rb
404
- - test/test_scp.rb
405
- - test/test_strict.rb
406
- - test/test_various.rb
407
- - test/test_wab.rb
408
- - test/test_writer.rb
409
- - test/tests.rb
410
- - test/tests_mimic.rb
411
- - test/tests_mimic_addition.rb
412
- - test/zoo.rb
301
+ test_files: []
@@ -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
-