oj 3.7.12 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ Symbols. The same is true for auto defining classes in all versions of ruby;
7
7
  memory will also be exhausted if too many classes are automatically
8
8
  defined. Auto defining is a useful feature during development and from trusted
9
9
  sources but it allows too many classes to be created in the object load mode and
10
- auto defined is used with an untrusted source. The `Oj.strict_load()` method
10
+ auto defined is used with an untrusted source. The `Oj.safe_load()` method
11
11
  sets and uses the most strict and safest options. It should be used by
12
12
  developers who find it difficult to understand the options available in Oj.
13
13
 
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
6
+ %w(lib ext).each do |dir|
7
+ $: << File.join($oj_dir, dir)
8
+ end
9
+
10
+ require 'oj'
11
+
12
+ #Oj.load_file(ARGV[0], mode: :strict) { |obj|
13
+ # puts Oj.dump(obj, indent: 2)
14
+ #}
15
+
16
+ data = open('invalid_unicode.data').read
17
+
18
+ puts data
19
+
20
+ puts Oj.dump(data)
21
+
22
+ Oj.mimic_JSON
23
+ puts Oj.dump(data, escape_mode: :json)
24
+
25
+ puts Oj.default_options
@@ -1,33 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: UTF-8
2
3
 
3
- $: << '.'
4
- $: << '../lib'
5
- $: << '../ext'
4
+ $: << File.dirname(__FILE__)
5
+ $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
6
+ %w(lib ext).each do |dir|
7
+ $: << File.join($oj_dir, dir)
8
+ end
6
9
 
7
10
  require 'oj'
11
+ require 'active_support'
12
+ require 'active_support/json'
13
+ #require 'tracer'
8
14
 
9
- f = File.open("foo.json", "w")
10
- 100_000.times do
11
- obj = { created_at: DateTime.new(2001,2,3,4,5,6) }
12
- Oj.to_stream(f, obj)
13
- f.puts
14
- f.flush
15
- end
16
- f.close
15
+ Oj::Rails.set_encoder()
16
+ Oj::Rails.set_decoder()
17
+ Oj::Rails.optimize()
17
18
 
18
- def run_test_thread
19
- threads = Array.new(3) do
20
- Thread.new do
21
- counter = 0
22
- File.open("foo.json", "r") { |f| Oj.enum_for(:load, f).lazy.each { counter += 1 } }
23
- #File.open("odd_file.jsonl", "r") { |f| Oj.enum_for(:load, f).lazy.each { counter += 1 } }
24
- puts counter
25
- end
26
- end
27
- threads.each(&:join)
28
- end
19
+ #Oj::mimic_JSON
29
20
 
30
- 100.times do |i|
31
- puts i
32
- run_test_thread
33
- end
21
+ puts JSON.parse('{"a":1}', symbolize_names: true)
@@ -32,6 +32,9 @@ class CustomJuice < Minitest::Test
32
32
  def to_json(*args)
33
33
  %|{"xx":#{@x},"yy":#{y}}|
34
34
  end
35
+ def raw_json(depth, indent)
36
+ %|{"xxx":#{@x},"yyy":#{y}}|
37
+ end
35
38
  def as_json(*args)
36
39
  {'a' => @x, :b => @y }
37
40
  end
@@ -40,6 +43,40 @@ class CustomJuice < Minitest::Test
40
43
  end
41
44
  end
42
45
 
46
+ class AsJson
47
+ attr_accessor :x, :y
48
+
49
+ def initialize(x, y)
50
+ @x = x
51
+ @y = y
52
+ end
53
+ def ==(o)
54
+ self.class == o.class && @x == o.x && @y = o.y
55
+ end
56
+ def as_json(*args)
57
+ {'a' => @x, :b => @y }
58
+ end
59
+ end
60
+
61
+ class AsRails
62
+ attr_accessor :x, :y
63
+
64
+ def initialize(x, y)
65
+ @x = x
66
+ @y = y
67
+ end
68
+ def ==(o)
69
+ self.class == o.class && @x == o.x && @y = o.y
70
+ end
71
+ def as_json(*args)
72
+ a = @x
73
+ a = a.as_json if a.respond_to?('as_json')
74
+ b = @y
75
+ b = b.as_json if b.respond_to?('as_json')
76
+ {'a' => a, :b => b }
77
+ end
78
+ end
79
+
43
80
  def setup
44
81
  @default_options = Oj.default_options
45
82
  Oj.default_options = { :mode => :custom }
@@ -92,7 +129,7 @@ class CustomJuice < Minitest::Test
92
129
  end
93
130
  assert(false, "*** expected an exception")
94
131
  end
95
-
132
+
96
133
  def test_infinity_dump
97
134
  assert_equal('null', Oj.dump(1/0.0, :nan => :null))
98
135
  assert_equal('3.0e14159265358979323846', Oj.dump(1/0.0, :nan => :huge))
@@ -187,7 +224,7 @@ class CustomJuice < Minitest::Test
187
224
  '19' => {
188
225
  '20' => {}}}}}}}}}}}}}}}}}}}}}, false)
189
226
  end
190
-
227
+
191
228
  def test_hash_escaped_key
192
229
  json = %{{"a\nb":true,"c\td":false}}
193
230
  obj = Oj.load(json)
@@ -232,6 +269,66 @@ class CustomJuice < Minitest::Test
232
269
  assert_equal(%|{"b":true,"n":58}|, json)
233
270
  end
234
271
 
272
+ def test_object_raw_json
273
+ obj = Jeez.new(true, 58)
274
+ json = Oj.dump(obj, :use_to_json => true, :use_as_json => false, :use_raw_json => true, :use_to_hash => false)
275
+ assert_equal(%|{"xxx":true,"yyy":58}|, json)
276
+ end
277
+
278
+ def test_raw_json_stringwriter
279
+ obj = Oj::StringWriter.new(:indent => 0)
280
+ obj.push_array()
281
+ obj.pop()
282
+ json = Oj.dump(obj, :use_raw_json => true)
283
+ assert_equal(%|[]|, json)
284
+ end
285
+
286
+ def test_as_raw_json_stringwriter
287
+ obj = Oj::StringWriter.new(:indent => 0)
288
+ obj.push_array()
289
+ obj.push_value(3)
290
+ obj.pop()
291
+ j = AsJson.new(1, obj)
292
+
293
+ json = Oj.dump(j, use_raw_json: true, use_as_json: true, indent: 2)
294
+ assert_equal(%|{
295
+ "a":1,
296
+ "b":[3]
297
+ }
298
+ |, json)
299
+
300
+ json = Oj.dump(j, use_raw_json: false, use_as_json: true, indent: 2)
301
+ assert_equal(%|{
302
+ "a":1,
303
+ "b":{}
304
+ }
305
+ |, json)
306
+ end
307
+
308
+ def test_rails_as_raw_json_stringwriter
309
+ obj = Oj::StringWriter.new(:indent => 0)
310
+ obj.push_array()
311
+ obj.push_value(3)
312
+ obj.pop()
313
+ j = AsRails.new(1, obj)
314
+ json = Oj.dump(j, mode: :rails, use_raw_json: true, indent: 2)
315
+ assert_equal(%|{
316
+ "a":1,
317
+ "b":{}
318
+ }
319
+ |, json)
320
+
321
+ Oj::Rails.optimize
322
+ json = Oj.dump(j, mode: :rails, use_raw_json: true, indent: 2)
323
+ Oj::Rails.deoptimize
324
+ assert_equal(%|{
325
+ "a":1,
326
+ "b":[3]
327
+ }
328
+ |, json)
329
+
330
+ end
331
+
235
332
  def test_symbol
236
333
  json = Oj.dump(:abc)
237
334
  assert_equal('"abc"', json)
@@ -134,6 +134,7 @@ class Juice < Minitest::Test
134
134
  :use_to_json=>false,
135
135
  :use_to_hash=>false,
136
136
  :use_as_json=>false,
137
+ :use_raw_json=>false,
137
138
  :nilnil=>true,
138
139
  :empty_string=>true,
139
140
  :allow_gc=>false,
@@ -158,6 +159,7 @@ class Juice < Minitest::Test
158
159
  :array_class=>Array,
159
160
  :ignore=>nil,
160
161
  :trace=>true,
162
+ :safe=>true,
161
163
  }
162
164
  Oj.default_options = alt
163
165
  #keys = alt.keys
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #require 'json'
4
+
5
+ $: << File.dirname(__FILE__)
6
+ require 'helper'
7
+ require 'oj'
8
+
9
+ Oj.mimic_JSON
10
+ puts "\u3074"
11
+
12
+ puts JSON.dump(["\u3074"])
13
+ puts JSON.generate(["\u3074"])
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.7.12
4
+ version: 3.9.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: 2019-04-14 00:00:00.000000000 Z
11
+ date: 2019-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -79,16 +79,16 @@ extensions:
79
79
  - ext/oj/extconf.rb
80
80
  extra_rdoc_files:
81
81
  - README.md
82
- - pages/Modes.md
82
+ - pages/Rails.md
83
+ - pages/JsonGem.md
84
+ - pages/Encoding.md
85
+ - pages/WAB.md
86
+ - pages/Custom.md
83
87
  - pages/Advanced.md
84
88
  - pages/Options.md
85
- - pages/Custom.md
86
89
  - pages/Compatibility.md
87
- - pages/WAB.md
90
+ - pages/Modes.md
88
91
  - pages/Security.md
89
- - pages/Encoding.md
90
- - pages/JsonGem.md
91
- - pages/Rails.md
92
92
  files:
93
93
  - LICENSE
94
94
  - README.md
@@ -177,7 +177,7 @@ files:
177
177
  - test/activesupport5/encoding_test_cases.rb
178
178
  - test/activesupport5/test_helper.rb
179
179
  - test/activesupport5/time_zone_test_helpers.rb
180
- - test/big.rb
180
+ - test/bar.rb
181
181
  - test/files.rb
182
182
  - test/foo.rb
183
183
  - test/helper.rb
@@ -200,7 +200,6 @@ files:
200
200
  - test/json_gem/json_parser_test.rb
201
201
  - test/json_gem/json_string_matching_test.rb
202
202
  - test/json_gem/test_helper.rb
203
- - test/mem.rb
204
203
  - test/perf.rb
205
204
  - test/perf_compat.rb
206
205
  - test/perf_fast.rb
@@ -244,6 +243,7 @@ files:
244
243
  - test/tests.rb
245
244
  - test/tests_mimic.rb
246
245
  - test/tests_mimic_addition.rb
246
+ - test/zoo.rb
247
247
  homepage: http://www.ohler.com/oj
248
248
  licenses:
249
249
  - MIT
@@ -266,7 +266,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
266
  requirements:
267
267
  - - ">="
268
268
  - !ruby/object:Gem::Version
269
- version: '2.0'
269
+ version: '2.3'
270
270
  required_rubygems_version: !ruby/object:Gem::Requirement
271
271
  requirements:
272
272
  - - ">="
@@ -278,82 +278,82 @@ signing_key:
278
278
  specification_version: 4
279
279
  summary: A fast JSON parser and serializer.
280
280
  test_files:
281
- - test/perf_file.rb
282
- - test/test_hash.rb
283
- - test/perf.rb
284
- - test/test_object.rb
285
- - test/test_null.rb
286
- - test/test_compat.rb
287
- - test/test_custom.rb
288
- - test/perf_scp.rb
281
+ - test/foo.rb
289
282
  - test/test_integer_range.rb
290
- - test/test_gc.rb
291
- - test/sample.rb
292
- - test/json_gem/json_string_matching_test.rb
283
+ - test/test_strict.rb
284
+ - test/perf_strict.rb
285
+ - test/tests.rb
286
+ - test/perf_saj.rb
287
+ - test/test_compat.rb
288
+ - test/helper.rb
289
+ - test/perf_file.rb
290
+ - test/test_scp.rb
291
+ - test/perf_compat.rb
292
+ - test/json_gem/json_common_interface_test.rb
293
293
  - test/json_gem/json_addition_test.rb
294
- - test/json_gem/test_helper.rb
294
+ - test/json_gem/json_fixtures_test.rb
295
+ - test/json_gem/json_ext_parser_test.rb
296
+ - test/json_gem/json_string_matching_test.rb
297
+ - test/json_gem/json_generic_object_test.rb
295
298
  - test/json_gem/json_generator_test.rb
296
- - test/json_gem/json_parser_test.rb
299
+ - test/json_gem/test_helper.rb
297
300
  - test/json_gem/json_encoding_test.rb
298
- - test/json_gem/json_common_interface_test.rb
299
- - test/json_gem/json_generic_object_test.rb
300
- - test/json_gem/json_ext_parser_test.rb
301
- - test/json_gem/json_fixtures_test.rb
302
- - test/tests_mimic_addition.rb
303
- - test/test_wab.rb
301
+ - test/json_gem/json_parser_test.rb
302
+ - test/perf_wab.rb
303
+ - test/test_file.rb
304
+ - test/test_object.rb
305
+ - test/sample.rb
306
+ - test/perf_object.rb
307
+ - test/test_hash.rb
308
+ - test/test_custom.rb
309
+ - test/bar.rb
310
+ - test/activesupport4/encoding_test.rb
304
311
  - test/activesupport4/test_helper.rb
305
312
  - test/activesupport4/decoding_test.rb
306
- - test/activesupport4/encoding_test.rb
307
- - test/activerecord/result_test.rb
308
- - test/_test_active.rb
309
- - test/test_file.rb
313
+ - test/sample_json.rb
310
314
  - test/activesupport5/encoding_test_cases.rb
315
+ - test/activesupport5/encoding_test.rb
311
316
  - test/activesupport5/time_zone_test_helpers.rb
312
317
  - test/activesupport5/test_helper.rb
313
318
  - test/activesupport5/decoding_test.rb
314
- - test/activesupport5/encoding_test.rb
315
- - test/tests.rb
316
- - test/_test_active_mimic.rb
317
- - test/perf_object.rb
318
- - test/test_strict.rb
319
- - test/test_scp.rb
320
- - test/perf_wab.rb
321
319
  - test/test_saj.rb
322
- - test/mem.rb
323
- - test/perf_compat.rb
324
- - test/helper.rb
325
- - test/isolated/test_mimic_alone.rb
326
- - test/isolated/test_mimic_define.rb
327
- - test/isolated/test_mimic_rails_after.rb
328
- - test/isolated/test_mimic_after.rb
329
- - test/isolated/test_mimic_rails_before.rb
330
- - test/isolated/test_mimic_as_json.rb
331
- - test/isolated/test_mimic_redefine.rb
332
- - test/isolated/shared.rb
333
- - test/isolated/test_mimic_before.rb
334
- - test/sample_json.rb
335
- - test/test_debian.rb
336
- - test/perf_fast.rb
337
- - test/test_writer.rb
320
+ - test/perf_scp.rb
321
+ - test/test_wab.rb
322
+ - test/test_null.rb
323
+ - test/_test_active.rb
324
+ - test/_test_mimic_rails.rb
338
325
  - test/test_fast.rb
339
- - test/sample/line.rb
326
+ - test/perf_fast.rb
340
327
  - test/sample/change.rb
341
- - test/sample/dir.rb
342
328
  - test/sample/text.rb
343
- - test/sample/layer.rb
344
- - test/sample/rect.rb
345
- - test/sample/group.rb
346
- - test/sample/oval.rb
347
329
  - test/sample/doc.rb
348
- - test/sample/hasprops.rb
349
330
  - test/sample/shape.rb
331
+ - test/sample/layer.rb
332
+ - test/sample/group.rb
350
333
  - test/sample/file.rb
351
- - test/files.rb
352
- - test/big.rb
353
- - test/perf_saj.rb
354
- - test/foo.rb
334
+ - test/sample/rect.rb
335
+ - test/sample/hasprops.rb
336
+ - test/sample/line.rb
337
+ - test/sample/dir.rb
338
+ - test/sample/oval.rb
355
339
  - test/tests_mimic.rb
356
- - test/perf_strict.rb
357
- - test/test_various.rb
358
- - test/_test_mimic_rails.rb
359
340
  - test/perf_simple.rb
341
+ - test/zoo.rb
342
+ - test/activerecord/result_test.rb
343
+ - test/_test_active_mimic.rb
344
+ - test/tests_mimic_addition.rb
345
+ - test/test_writer.rb
346
+ - test/perf.rb
347
+ - test/isolated/test_mimic_define.rb
348
+ - test/isolated/test_mimic_after.rb
349
+ - test/isolated/test_mimic_rails_after.rb
350
+ - test/isolated/test_mimic_before.rb
351
+ - test/isolated/test_mimic_rails_before.rb
352
+ - test/isolated/test_mimic_redefine.rb
353
+ - test/isolated/shared.rb
354
+ - test/isolated/test_mimic_alone.rb
355
+ - test/isolated/test_mimic_as_json.rb
356
+ - test/test_debian.rb
357
+ - test/test_gc.rb
358
+ - test/files.rb
359
+ - test/test_various.rb