oj 3.10.6 → 3.10.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6c2164398794345431cbf21fe2598c7a68498dc21a49868103f9227470c5cdc
4
- data.tar.gz: 81ddcee2018723c2ca4a9c668d78043d60647a83ab99057cdce3bd92ebad56fd
3
+ metadata.gz: 21e870cbb9a2f1c2b99efd6522ce9c284828865b922e299232e60abd4e916f7e
4
+ data.tar.gz: d1d93c3d58b7ed858e1a4ea89698861485bbeeb19b01bc66e3e8890ab7d93583
5
5
  SHA512:
6
- metadata.gz: 546bcdf0ee93a8b170970ac0a9e26497ee4b903f606f1fc2640e77093765ea9d63d58501c4472fb742d810ac1adddbb31caaaa19b2cf984af1b0345b529a4aa3
7
- data.tar.gz: 51745a18bc008d4ba5bac4a459ec2231997998efdf56de1e56b3bdd2b5e972733ed12a43be7ff10f54827825ae7e9a5c3532629c044f4c71ebe0934a05e2d334
6
+ metadata.gz: 7c5d6b2d7a7830b80ecc23436e50b0f42f53e82febe31ceb0168f440e5368ed323c19433894724beea83e7587013170b6a38be92b65b073d9881f8176a8d283b
7
+ data.tar.gz: 1558090a4a1b066418b9f36064c845ab99e423246f26af8aff682e8f09b8cfce29531f6e677c6e4d8b16056406251b2fe54b463e4ddef121adced8c9d3c167b2
@@ -453,6 +453,7 @@ read_num(ParseInfo pi) {
453
453
  // except when mimicing the JSON gem or in strict mode.
454
454
  if (StrictMode == pi->options.mode || CompatMode == pi->options.mode) {
455
455
  int pos = (int)(pi->cur - ni.str);
456
+
456
457
  if (1 == pos || (2 == pos && ni.neg)) {
457
458
  oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number");
458
459
  return;
@@ -468,11 +469,19 @@ read_num(ParseInfo pi) {
468
469
  if (0 < ni.num || 0 < ni.i) {
469
470
  dec_cnt++;
470
471
  }
471
- ni.num = ni.num * 10 + d;
472
- ni.div *= 10;
473
- ni.di++;
474
- if (INT64_MAX <= ni.div || DEC_MAX < dec_cnt) {
475
- ni.big = 1;
472
+ if (INT64_MAX <= ni.div) {
473
+ if (!ni.no_big) {
474
+ ni.big = true;
475
+ }
476
+ } else {
477
+ ni.num = ni.num * 10 + d;
478
+ ni.div *= 10;
479
+ ni.di++;
480
+ if (INT64_MAX <= ni.div || DEC_MAX < dec_cnt) {
481
+ if (!ni.no_big) {
482
+ ni.big = true;
483
+ }
484
+ }
476
485
  }
477
486
  }
478
487
  }
@@ -490,7 +499,7 @@ read_num(ParseInfo pi) {
490
499
  for (; '0' <= *pi->cur && *pi->cur <= '9'; pi->cur++) {
491
500
  ni.exp = ni.exp * 10 + (*pi->cur - '0');
492
501
  if (EXP_MAX <= ni.exp) {
493
- ni.big = 1;
502
+ ni.big = true;
494
503
  }
495
504
  }
496
505
  if (eneg) {
@@ -810,22 +819,35 @@ oj_num_as_value(NumInfo ni) {
810
819
  }
811
820
  } else {
812
821
  double d;
822
+ double d2;
813
823
 
814
824
  ld = roundl(ld);
815
825
  // You would expect that staying with a long double would be
816
826
  // more accurate but it fails to match what Ruby generates so
817
827
  // drop down to a double.
818
828
  if (0 < x) {
819
- d = (double)ld * pow(10.0, x);
829
+ d = (double)(ld * powl(10.0, x));
830
+ d2 = (double)ld * pow(10.0, x);
820
831
  } else if (0 > x) {
821
- d = (double)ld / pow(10.0, -x);
832
+ d = (double)(ld / powl(10.0, -x));
833
+ d2 = (double)ld / pow(10.0, -x);
822
834
  } else {
823
835
  d = (double)ld;
836
+ d2 = d;
824
837
  }
825
- if (ni->neg) {
826
- d = -d;
838
+ if (d != d2) {
839
+ volatile VALUE bd = rb_str_new(ni->str, ni->len);
840
+
841
+ rnum = rb_rescue2(parse_big_decimal, bd, rescue_big_decimal, bd, rb_eException, 0);
842
+ if (ni->no_big) {
843
+ rnum = rb_funcall(rnum, rb_intern("to_f"), 0);
844
+ }
845
+ } else {
846
+ if (ni->neg) {
847
+ d = -d;
848
+ }
849
+ rnum = rb_float_new(d);
827
850
  }
828
- rnum = rb_float_new(d);
829
851
  }
830
852
  }
831
853
  }
@@ -848,6 +870,12 @@ oj_set_error_at(ParseInfo pi, VALUE err_clas, const char* file, int line, const
848
870
  if (p + 3 < end) {
849
871
  *p++ = ' ';
850
872
  *p++ = '(';
873
+ *p++ = 'a';
874
+ *p++ = 'f';
875
+ *p++ = 't';
876
+ *p++ = 'e';
877
+ *p++ = 'r';
878
+ *p++ = ' ';
851
879
  start = p;
852
880
  for (vp = pi->stack.head; vp < pi->stack.tail; vp++) {
853
881
  if (end <= p + 1 + vp->klen) {
@@ -409,6 +409,7 @@ read_num(ParseInfo pi) {
409
409
  ni.neg = 0;
410
410
  ni.hasExp = 0;
411
411
  ni.no_big = (FloatDec == pi->options.bigdec_load);
412
+
412
413
  c = reader_get(&pi->rd);
413
414
  if ('-' == c) {
414
415
  c = reader_get(&pi->rd);
@@ -469,11 +470,19 @@ read_num(ParseInfo pi) {
469
470
  if (0 < ni.num || 0 < ni.i) {
470
471
  dec_cnt++;
471
472
  }
472
- ni.num = ni.num * 10 + d;
473
- ni.div *= 10;
474
- ni.di++;
475
- if (INT64_MAX <= ni.div || DEC_MAX < dec_cnt) {
476
- ni.big = 1;
473
+ if (INT64_MAX <= ni.div) {
474
+ if (!ni.no_big) {
475
+ ni.big = true;
476
+ }
477
+ } else {
478
+ ni.num = ni.num * 10 + d;
479
+ ni.div *= 10;
480
+ ni.di++;
481
+ if (INT64_MAX <= ni.div || DEC_MAX < dec_cnt) {
482
+ if (!ni.no_big) {
483
+ ni.big = true;
484
+ }
485
+ }
477
486
  }
478
487
  }
479
488
  }
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.10.6'
4
+ VERSION = '3.10.7'
5
5
  end
@@ -80,16 +80,16 @@ dynamically modifying classes or reloading classes then don't use this.
80
80
 
81
81
  ### :create_additions
82
82
 
83
- A flag indicating the :create_id key when encountered during parsing should
84
- creating an Object mactching the class name specified in the value associated
85
- with the key.
83
+ A flag indicating that the :create_id key, when encountered during parsing,
84
+ should create an Object matching the class name specified in the value
85
+ associated with the key.
86
86
 
87
87
  ### :create_id [String]
88
88
 
89
89
  The :create_id option specifies that key is used for dumping and loading when
90
90
  specifying the class for an encoded object. The default is `json_create`.
91
91
 
92
- In the `:custom` mode setting the `:create_id` to nil will cause Complex,
92
+ In the `:custom` mode, setting the `:create_id` to nil will cause Complex,
93
93
  Rational, Range, and Regexp to be output as strings instead of as JSON
94
94
  objects.
95
95
 
@@ -179,7 +179,7 @@ customization.
179
179
  ### :nan [Symbol]
180
180
 
181
181
  How to dump Infinity, -Infinity, and NaN in :null, :strict, and :compat
182
- mode. Default is :auto but is ignored in the :compat and :rails mode.
182
+ mode. Default is :auto but is ignored in the :compat and :rails modes.
183
183
 
184
184
  - `:null` places a null
185
185
 
@@ -252,7 +252,7 @@ The :time_format when dumping.
252
252
 
253
253
  - `:unix` time is output as a decimal number in seconds since epoch including fractions of a second.
254
254
 
255
- - `:unix_zone` similar to the `:unix` format but with the timezone encoded in
255
+ - `:unix_zone` is similar to the `:unix` format but with the timezone encoded in
256
256
  the exponent of the decimal number of seconds since epoch.
257
257
 
258
258
  - `:xmlschema` time is output as a string that follows the XML schema definition.
@@ -262,16 +262,16 @@ The :time_format when dumping.
262
262
  ### :use_as_json [Boolean]
263
263
 
264
264
  Call `as_json()` methods on dump, default is false. The option is ignored in
265
- the :compat and :rails mode.
265
+ the :compat and :rails modes.
266
266
 
267
267
 
268
268
  ### :use_raw_json [Boolean]
269
269
 
270
270
  Call `raw_json()` methods on dump, default is false. The option is
271
- accepted in the :compat and :rails mode even though it is not
271
+ accepted in the :compat and :rails modes even though it is not
272
272
  supported by other JSON gems. It provides a means to optimize dump or
273
273
  generate performance. The `raw_json(depth, indent)` method should be
274
- called only by Oj. It is not intended for any other use. This is mean
274
+ called only by Oj. It is not intended for any other use. This is meant
275
275
  to replace the abused `to_json` methods. Calling `Oj.dump` inside the
276
276
  `raw_json` with the object itself when `:use_raw_json` is true will
277
277
  result in an infinite loop.
@@ -279,9 +279,9 @@ result in an infinite loop.
279
279
  ### :use_to_hash [Boolean]
280
280
 
281
281
  Call `to_hash()` methods on dump, default is false. The option is ignored in
282
- the :compat and :rails mode.
282
+ the :compat and :rails modes.
283
283
 
284
284
  ### :use_to_json [Boolean]
285
285
 
286
286
  Call `to_json()` methods on dump, default is false. The option is ignored in
287
- the :compat and :rails mode.
287
+ the :compat and :rails modes.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oj'
4
+
5
+ extras = {"locationLng" => -97.14690769100295}
6
+
7
+ Oj.default_options = {float_precision: 17}
8
+
9
+ encoded = Oj.dump(extras)
10
+ puts encoded
11
+ puts Oj.load(encoded)
12
+
13
+ require "active_record"
14
+
15
+ Oj::Rails.set_encoder()
16
+ Oj::Rails.set_decoder()
17
+
18
+ Oj.default_options = {float_precision: 17}
19
+ # Using Oj rails encoder, gets the correct value: {"locationLng":-97.14690769100295}
20
+ encoded = ActiveSupport::JSON.encode(extras)
21
+ puts encoded
22
+ puts ActiveSupport::JSON.decode(encoded)
23
+ puts Oj.load(encoded)
@@ -118,6 +118,11 @@ class CustomJuice < Minitest::Test
118
118
  dump_and_load(-2.48e100 * 1.0e10, false)
119
119
  end
120
120
 
121
+ def test_float_parse
122
+ f = Oj.load("12.123456789012345678", mode: :custom, bigdecimal_load: :float);
123
+ assert_equal(Float, f.class)
124
+ end
125
+
121
126
  def test_nan_dump
122
127
  assert_equal('null', Oj.dump(0/0.0, :nan => :null))
123
128
  assert_equal('3.3e14159265358979323846', Oj.dump(0/0.0, :nan => :huge))
@@ -185,7 +185,6 @@ class Juice < Minitest::Test
185
185
  n = Oj.load('-0.000012345678901234567')
186
186
  assert_equal(BigDecimal, n.class)
187
187
  assert_equal('-0.12345678901234567E-4', n.to_s.upcase)
188
-
189
188
  end
190
189
 
191
190
  =begin
@@ -671,7 +670,7 @@ class Juice < Minitest::Test
671
670
  raise e
672
671
  end
673
672
  }
674
- assert_equal('first[2].third', msg.split('(')[1].split(')')[0])
673
+ assert_equal('after first[2].third', msg.split('(')[1].split(')')[0])
675
674
  end
676
675
 
677
676
  def test_bad_bignum
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.10.6
4
+ version: 3.10.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-04 00:00:00.000000000 Z
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -219,6 +219,7 @@ files:
219
219
  - test/perf_simple.rb
220
220
  - test/perf_strict.rb
221
221
  - test/perf_wab.rb
222
+ - test/prec.rb
222
223
  - test/sample.rb
223
224
  - test/sample/change.rb
224
225
  - test/sample/dir.rb
@@ -289,6 +290,7 @@ specification_version: 4
289
290
  summary: A fast JSON parser and serializer.
290
291
  test_files:
291
292
  - test/foo.rb
293
+ - test/prec.rb
292
294
  - test/test_integer_range.rb
293
295
  - test/test_strict.rb
294
296
  - test/perf_strict.rb