oj 3.10.1 → 3.10.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dd1cae4ccf720f35b777913213b66466c7d9752055c60d828cdf681956731a3
4
- data.tar.gz: e913c57a4619bfbea97144f6f4783219aca294e598c8c6449ddfc6cb997b46f7
3
+ metadata.gz: 3c5237f8fde35d255bce0e58bbb8de4cd74e6e1f8ea563ce6413eeec4605ec46
4
+ data.tar.gz: 97eeb9614491ed377ad2336bda388e0d3eeac843d61d4afea44e80bcf9e7782b
5
5
  SHA512:
6
- metadata.gz: dc0b7bd0e9ea90e69eda6a6205c09540e2217f9ccdcb3c6e937fb82e4b979fada30a028b64559ac5dfddc22afb9d4302669de35315bb5c5392ad100a373bb472
7
- data.tar.gz: 8d8ad9eeb68fb2d058c3f499ad51fc8c50d3349b36a237769f996a43de58449fbae36d3bff82c6be6a16828331f12aa19df6a1ef90b5bdff78ecdf732450a268
6
+ metadata.gz: 7fd89f9ca4e2ef290e4096d3d486f118ab5cf93b3b54f14b0873561f0ec486ab700ac04e3556db6bd7a82f53e81d10f00eb7ecb524a012266018b9b080c89726
7
+ data.tar.gz: 0436f2949fc7881f194c6f781f489a9a47dbacb630390308fc1b48c2e047cbbc160338ab51f94998c9a08f39e996c9db27a4dd341d7870299de78d41f2d8a659
@@ -111,7 +111,7 @@ static char rails_friendly_chars[256] = "\
111
111
  11111111111111111111111111111111\
112
112
  11111111111111111111111111111111\
113
113
  11111111111111111111111111111111\
114
- 11611111111111111111111111111111";
114
+ 11111111111111111111111111111111";
115
115
 
116
116
  static void
117
117
  raise_strict(VALUE obj) {
@@ -669,7 +669,8 @@ static void
669
669
  array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
670
670
  volatile VALUE rval = Qnil;
671
671
 
672
- if (3 <= len && 0 != pi->circ_array) {
672
+ // orig lets us know whether the string was ^r1 or \u005er1
673
+ if (3 <= len && 0 != pi->circ_array && '^' == orig[0] && 0 == rb_array_len(stack_peek(&pi->stack)->val)) {
673
674
  if ('i' == str[1]) {
674
675
  long i = read_long(str + 2, len - 2);
675
676
 
@@ -795,13 +795,13 @@ oj_num_as_value(NumInfo ni) {
795
795
  }
796
796
  } else {
797
797
  // All these machinations are to get rounding to work better.
798
- long double d = (long double)ni->i * (long double)ni->div + (long double)ni->num;
798
+ long double ld = (long double)ni->i * (long double)ni->div + (long double)ni->num;
799
799
  int x = (int)((int64_t)ni->exp - ni->di);
800
800
 
801
801
  // Rounding sometimes cuts off the last digit even if there are only
802
802
  // 15 digits. This attempts to fix those few cases where this
803
803
  // occurs.
804
- if ((long double)INT64_MAX > d && (int64_t)d != (ni->i * ni->div + ni->num)) {
804
+ if ((long double)INT64_MAX > ld && (int64_t)ld != (ni->i * ni->div + ni->num)) {
805
805
  volatile VALUE bd = rb_str_new(ni->str, ni->len);
806
806
 
807
807
  rnum = rb_rescue2(parse_big_decimal, bd, rescue_big_decimal, bd, rb_eException, 0);
@@ -809,16 +809,23 @@ oj_num_as_value(NumInfo ni) {
809
809
  rnum = rb_funcall(rnum, rb_intern("to_f"), 0);
810
810
  }
811
811
  } else {
812
- d = roundl(d);
812
+ double d;
813
+
814
+ ld = roundl(ld);
815
+ // You would expect that staying with a long double would be
816
+ // more accurate but it fails to match what Ruby generates so
817
+ // drop down to a double.
813
818
  if (0 < x) {
814
- d *= powl(10.0L, x);
819
+ d = (double)ld * pow(10.0, x);
815
820
  } else if (0 > x) {
816
- d /= powl(10.0L, -x);
821
+ d = (double)ld / pow(10.0, -x);
822
+ } else {
823
+ d = (double)ld;
817
824
  }
818
825
  if (ni->neg) {
819
826
  d = -d;
820
827
  }
821
- rnum = rb_float_new((double)d);
828
+ rnum = rb_float_new(d);
822
829
  }
823
830
  }
824
831
  }
@@ -1012,7 +1012,6 @@ rails_encode(int argc, VALUE *argv, VALUE self) {
1012
1012
  }
1013
1013
  }
1014
1014
 
1015
- // TBD provide a get function as well
1016
1015
  static VALUE
1017
1016
  rails_use_standard_json_time_format(VALUE self, VALUE state) {
1018
1017
  if (Qtrue == state || Qfalse == state) {
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.10.1'
4
+ VERSION = '3.10.5'
5
5
  end
@@ -80,6 +80,45 @@ The classes that can be put in optimized mode and are optimized when
80
80
  The ActiveSupport decoder is the `JSON.parse()` method. Calling the
81
81
  `Oj::Rails.set_decoder()` method replaces that method with the Oj equivalent.
82
82
 
83
+ ### Usage in Rails 3
84
+
85
+ To support Rails 3 you can create a new module mixin to prepend to controllers:
86
+
87
+ ```ruby
88
+ require 'oj'
89
+
90
+ module OjJsonEncoder
91
+ def render(options = nil, extra_options = {}, &block)
92
+ if options && options.is_a?(Hash) && options[:json]
93
+ obj = options.delete(:json)
94
+ obj = Oj.dump(obj, :mode => :rails) unless obj.is_a?(String)
95
+ options[:text] = obj
96
+ response.content_type ||= Mime::JSON
97
+ end
98
+ super
99
+ end
100
+ end
101
+ ```
102
+
103
+ Usage:
104
+
105
+ ```ruby
106
+ class MyController < ApplicationController
107
+ prepend OjJsonEncoder
108
+ def index
109
+ render :json => { :hello => 'world' }
110
+ end
111
+ end
112
+ ```
113
+
114
+ ### Older Ruby Version Support (Pre 2.3.0)
115
+
116
+ If you are using an older version of Ruby, you can pin `oj` to an earlier version in your Gemfile:
117
+
118
+ ```ruby
119
+ gem 'oj', '3.7.12'
120
+ ```
121
+
83
122
  ### Notes:
84
123
 
85
124
  1. Optimized Floats set the significant digits to 16. This is different than
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
2
 
4
3
  $: << File.dirname(__FILE__)
5
4
  $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
@@ -7,16 +6,30 @@ $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
7
6
  $: << File.join($oj_dir, dir)
8
7
  end
9
8
 
10
- require 'rails'
11
9
  require 'active_support'
12
- require 'active_support/json'
10
+ require "active_support/json"
13
11
 
14
- require 'oj'
12
+ $s = "\u2014 & \n \u{1F618}"
13
+
14
+ =begin
15
+ def check(label)
16
+ puts "\n--- #{label} --------------------"
17
+
18
+ ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
19
+ puts "with standard_json == true: t.to_json - #{$t.to_json}"
20
+ ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
21
+ puts "with standard_json == false: t.to_json - #{$t.to_json}"
22
+ end
23
+
24
+ check('Before Oj')
25
+ =end
15
26
 
16
- puts Rails::VERSION::STRING
27
+ require 'oj'
17
28
 
18
- #Oj.optimize_rails
29
+ ActiveSupport::JSON::Encoding.escape_html_entities_in_json = false
30
+ puts "ActiveSupport.encode(s) - #{ActiveSupport::JSON.encode($s)}"
19
31
 
20
- h = {foo: "bar"}
32
+ Oj.optimize_rails
33
+ Oj.default_options = { mode: :rails }
21
34
 
22
- puts Oj.dump(h, mode: :rails)
35
+ puts "Oj.dump(s) - #{Oj.dump($s)}"
@@ -15,7 +15,7 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase
15
15
  def setup
16
16
  @hash = {
17
17
  'a' => 2,
18
- 'b' => 3.141,
18
+ 'b' => 5.23683071,
19
19
  'c' => 'c',
20
20
  'd' => [ 1, "b", 3.14 ],
21
21
  'e' => { 'foo' => 'bar' },
@@ -23,7 +23,7 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase
23
23
  'h' => 1000.0,
24
24
  'i' => 0.001
25
25
  }
26
- @json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},'\
26
+ @json = '{"a":2,"b":5.23683071,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},'\
27
27
  '"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
28
28
  end
29
29
 
@@ -869,6 +869,14 @@ class ObjectJuice < Minitest::Test
869
869
  assert_equal(a2[1].__id__, a2.__id__)
870
870
  end
871
871
 
872
+ def test_circular_array3
873
+ a = ['^r1']
874
+ json = Oj.dump(a, mode: :object, circular: true)
875
+ assert_equal(%{["^i1","\\u005er1"]}, json)
876
+ a2 = Oj.load(json, mode: :object, circular: true)
877
+ assert_equal(a, a2)
878
+ end
879
+
872
880
  def test_circular_hash2
873
881
  h = { 'a' => 7 }
874
882
  h['b'] = h
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.1
4
+ version: 3.10.5
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-01-14 00:00:00.000000000 Z
11
+ date: 2020-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -283,7 +283,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
283
283
  - !ruby/object:Gem::Version
284
284
  version: '0'
285
285
  requirements: []
286
- rubygems_version: 3.0.3
286
+ rubygems_version: 3.1.2
287
287
  signing_key:
288
288
  specification_version: 4
289
289
  summary: A fast JSON parser and serializer.