oj 3.13.9 → 3.16.1

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