oj 3.15.0 → 3.16.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -142,6 +142,8 @@ class JSONGeneratorTest < Test::Unit::TestCase
142
142
  # seems to occur on travis but not locally.
143
143
  actual = state.to_h
144
144
  actual.delete(:escape_slash)
145
+ actual.delete(:strict)
146
+ actual.delete(:script_safe)
145
147
  assert_equal({
146
148
  :allow_nan => false,
147
149
  :array_nl => "\n",
@@ -162,6 +164,8 @@ class JSONGeneratorTest < Test::Unit::TestCase
162
164
  # seems to occur on travis but not locally.
163
165
  actual = state.to_h
164
166
  actual.delete(:escape_slash)
167
+ actual.delete(:strict)
168
+ actual.delete(:script_safe)
165
169
  assert_equal({
166
170
  :allow_nan => false,
167
171
  :array_nl => "",
@@ -182,6 +186,8 @@ class JSONGeneratorTest < Test::Unit::TestCase
182
186
  # seems to occur on travis but not locally.
183
187
  actual = state.to_h
184
188
  actual.delete(:escape_slash)
189
+ actual.delete(:strict)
190
+ actual.delete(:script_safe)
185
191
  assert_equal({
186
192
  :allow_nan => false,
187
193
  :array_nl => "",
@@ -352,7 +358,7 @@ class JSONGeneratorTest < Test::Unit::TestCase
352
358
  too_deep_ary = eval too_deep
353
359
  assert_raise(JSON::NestingError) { JSON.generate too_deep_ary }
354
360
  assert_raise(JSON::NestingError) { JSON.generate too_deep_ary, :max_nesting => 100 }
355
- ok = JSON.generate too_deep_ary, :max_nesting => 101
361
+ ok = JSON.generate too_deep_ary, :max_nesting => 102
356
362
  assert_equal too_deep, ok
357
363
  ok = JSON.generate too_deep_ary, :max_nesting => nil
358
364
  assert_equal too_deep, ok
data/test/perf_dump.rb CHANGED
@@ -24,11 +24,11 @@ opts.parse(ARGV)
24
24
  @obj = {
25
25
  'a' => 'Alpha', # string
26
26
  'b' => true, # boolean
27
- 'c' => 12345, # number
28
- 'd' => [ true, [false, [-123456789, nil], 3.9676, ['Something else.', false], nil]], # mix it up array
27
+ 'c' => 12_345, # number
28
+ 'd' => [ true, [false, [-123_456_789, nil], 3.9676, ['Something else.', false], nil]], # mix it up array
29
29
  'e' => { 'zero' => nil, 'one' => 1, 'two' => 2, 'three' => [3], 'four' => [0, 1, 2, 3, 4] }, # hash
30
30
  'f' => nil, # nil
31
- 'h' => { 'a' => { 'b' => { 'c' => { 'd' => {'e' => { 'f' => { 'g' => nil }}}}}}}, # deep hash, not that deep
31
+ 'h' => { 'a' => { 'b' => { 'c' => { 'd' => { 'e' => { 'f' => { 'g' => nil }}}}}}}, # deep hash, not that deep
32
32
  'i' => [[[[[[[nil]]]]]]] # deep array, again, not that deep
33
33
  }
34
34
 
data/test/prec.rb CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'oj'
4
4
 
5
- extras = {'locationLng' => -97.14690769100295}
5
+ extras = { 'locationLng' => -97.14690769100295 }
6
6
 
7
- Oj.default_options = {float_precision: 17}
7
+ Oj.default_options = { float_precision: 17 }
8
8
 
9
9
  encoded = Oj.dump(extras)
10
10
  puts encoded
@@ -15,8 +15,8 @@ require 'active_record'
15
15
  Oj::Rails.set_encoder()
16
16
  Oj::Rails.set_decoder()
17
17
 
18
- Oj.default_options = {float_precision: 17}
19
- # Using Oj rails encoder, gets the correct value: {'locationLng':-97.14690769100295}
18
+ Oj.default_options = { float_precision: 17 }
19
+ # Using Oj rails encoder, gets the correct value: { 'locationLng':-97.14690769100295 }
20
20
  encoded = ActiveSupport::JSON.encode(extras)
21
21
  puts encoded
22
22
  puts ActiveSupport::JSON.decode(encoded)
data/test/test_compat.rb CHANGED
@@ -467,10 +467,28 @@ class CompatJuice < Minitest::Test
467
467
  end
468
468
 
469
469
  def test_arg_passing
470
- json = Oj.to_json(Argy.new(), :max_nesting=> 40)
470
+ json = Oj.to_json(Argy.new(), :max_nesting => 40)
471
471
  assert_equal(%|{"args":"[{:max_nesting=>40}]"}|, json)
472
472
  end
473
473
 
474
+ def test_max_nesting
475
+ assert_raises() { Oj.to_json([[[[[]]]]], :max_nesting => 3) }
476
+ assert_raises() { Oj.dump([[[[[]]]]], :max_nesting => 3, :mode=>:compat) }
477
+
478
+ assert_raises() { Oj.to_json([[]], :max_nesting => 1) }
479
+ assert_equal('[[]]', Oj.to_json([[]], :max_nesting => 2))
480
+
481
+ assert_raises() { Oj.dump([[]], :max_nesting => 1, :mode=>:compat) }
482
+ assert_equal('[[]]', Oj.dump([[]], :max_nesting => 2, :mode=>:compat))
483
+
484
+ assert_raises() { Oj.to_json([[3]], :max_nesting => 1) }
485
+ assert_equal('[[3]]', Oj.to_json([[3]], :max_nesting => 2))
486
+
487
+ assert_raises() { Oj.dump([[3]], :max_nesting => 1, :mode=>:compat) }
488
+ assert_equal('[[3]]', Oj.dump([[3]], :max_nesting => 2, :mode=>:compat))
489
+
490
+ end
491
+
474
492
  def test_bad_unicode
475
493
  assert_raises() { Oj.to_json("\xE4xy") }
476
494
  end
data/test/test_custom.rb CHANGED
@@ -503,8 +503,9 @@ class CustomJuice < Minitest::Test
503
503
  # These two forms will lose precision while dumping as they don't
504
504
  # preserve full precision. We check that a dumped version is equal
505
505
  # to that version loaded and dumped a second time, but don't check
506
- # that the loaded Ruby objects is still the same as the original.
506
+ # that the loaded Ruby object is still the same as the original.
507
507
  dump_load_dump(obj, false, :time_format => :xmlschema, :create_id => '^o', :create_additions => true)
508
+ dump_load_dump(obj, false, :time_format => :xmlschema, :create_id => '^o', :create_additions => true, second_precision: 3)
508
509
  dump_load_dump(obj, false, :time_format => :ruby, :create_id => '^o', :create_additions => true)
509
510
  end
510
511
 
data/test/test_object.rb CHANGED
@@ -951,6 +951,20 @@ class ObjectJuice < Minitest::Test
951
951
  dump_and_load(DateTime.new(2012, 6, 19, 13, 5, Rational(7_123_456_789, 1_000_000_000)), false)
952
952
  end
953
953
 
954
+ def test_odd_xml_time
955
+ str = "2023-01-01T00:00:00Z"
956
+ assert_equal(Time.parse(str), Oj.load('{"^t":"' + str + '"}', mode: :object))
957
+
958
+ str = "2023-01-01T00:00:00.3Z"
959
+ assert_equal(Time.parse(str), Oj.load('{"^t":"' + str + '"}', mode: :object))
960
+
961
+ str = "2023-01-01T00:00:00.123456789123456789Z"
962
+ assert_equal(Time.parse(str), Oj.load('{"^t":"' + str + '"}', mode: :object))
963
+
964
+ str = "2023-01-01T00:00:00.123456789123456789123456789Z"
965
+ assert_equal(Time.parse(str), Oj.load('{"^t":"' + str + '"}', mode: :object))
966
+ end
967
+
954
968
  def test_bag
955
969
  json = %{{
956
970
  "^o":"ObjectJuice::Jem",
@@ -3,7 +3,7 @@
3
3
 
4
4
  $LOAD_PATH << __dir__
5
5
  @oj_dir = File.dirname(File.expand_path(__dir__))
6
- %w(lib ext).each do |dir|
6
+ %w[lib ext].each do |dir|
7
7
  $LOAD_PATH << File.join(@oj_dir, dir)
8
8
  end
9
9
 
@@ -147,6 +147,16 @@ class UsualTest < Minitest::Test
147
147
  assert_equal(MyHash, doc.class)
148
148
  end
149
149
 
150
+ def test_empty
151
+ p = Oj::Parser.new(:usual)
152
+ p.raise_on_empty = false
153
+ doc = p.parse(' ')
154
+ assert_nil(doc)
155
+
156
+ p.raise_on_empty = true
157
+ assert_raises(Oj::ParseError) { p.parse(' ') }
158
+ end
159
+
150
160
  class MyClass
151
161
  attr_accessor :a
152
162
  attr_accessor :b
data/test/test_strict.rb CHANGED
@@ -69,6 +69,16 @@ class StrictJuice < Minitest::Test
69
69
  dump_and_load(-2.48e100 * 1.0e10, false)
70
70
  end
71
71
 
72
+ def test_invalid_float
73
+ begin
74
+ Oj.load("64ecb72d29191067f91ff95b")
75
+ rescue Oj::ParseError => e
76
+ assert(e.message == "Invalid float")
77
+ return
78
+ end
79
+ assert(false, "*** expected an exception")
80
+ end
81
+
72
82
  def test_nan_dump
73
83
  assert_equal('null', Oj.dump(0/0.0, :nan => :null))
74
84
  assert_equal('3.3e14159265358979323846', Oj.dump(0/0.0, :nan => :huge))
data/test/test_various.rb CHANGED
@@ -105,6 +105,7 @@ class Juice < Minitest::Test
105
105
  allow_gc: false,
106
106
  quirks_mode: false,
107
107
  allow_invalid_unicode: true,
108
+ float_format: '%0.13g',
108
109
  float_precision: 13,
109
110
  mode: :strict,
110
111
  escape_mode: :ascii,
@@ -416,6 +417,11 @@ class Juice < Minitest::Test
416
417
  }
417
418
  end
418
419
 
420
+ def test_dump_float
421
+ json = Oj.dump(1.23e-2, :mode => :null, :float_format => '%0.4f')
422
+ assert_equal('0.0123', json)
423
+ end
424
+
419
425
  # Class
420
426
  def test_class_null
421
427
  json = Oj.dump(Juice, :mode => :null)
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.15.0
4
+ version: 3.16.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-06-03 00:00:00.000000000 Z
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bigdecimal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: minitest
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -294,7 +308,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
294
308
  - !ruby/object:Gem::Version
295
309
  version: '0'
296
310
  requirements: []
297
- rubygems_version: 3.4.1
311
+ rubygems_version: 3.4.10
298
312
  signing_key:
299
313
  specification_version: 4
300
314
  summary: A fast JSON parser and serializer.