oj 2.11.0 → 2.11.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oj might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4acaa9204b28018f0acc3ba755aa319759807b0
4
- data.tar.gz: 50e58cf7d4ac2265a74f234a6d8d9bff6b45b00d
3
+ metadata.gz: 6d3e4872cc8b3155f8547f4ab99ad2f0767ba878
4
+ data.tar.gz: 5ca0ea5af332edfdda45af2deca6323543395bfb
5
5
  SHA512:
6
- metadata.gz: b81caf19b41d35592c690f9e1c8411681a9ff0236eed9db198fdcc93e6a3b5463f5ef437849944b99808742f3ce91339d748a38bb687083e22f71bc1a658f788
7
- data.tar.gz: ba0df930d57755e5bbe0524ed88ff43542ef4a0177454fd139aa38cfcdf1801e63f73358e8f94d4e69ef6a55f972b3f162714c97212da734557afcec2080e914
6
+ metadata.gz: 951e8ce648c1afb634ef3b4b21387043dd918cc513b3f26c7966c5ef08c6ee03b41cb531ecc7065ac667612e334870a4ff3eac063606a626f799ea6a84ef3b24
7
+ data.tar.gz: 8c3fa952247342e7f58ce3c6a0966beba3dc89701a15fd72affa1cdcd1c2c5542df07db734753499cb363d51fba4a63e569ff31765cab006615d592c369ce60a
data/README.md CHANGED
@@ -26,30 +26,10 @@ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announceme
26
26
 
27
27
  [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
28
28
 
29
- ### Current Release 2.11.0
29
+ ### Current Release 2.11.1
30
30
 
31
- - Restricted strict dump to not dump NaN nor Infinity but instead raise an exception.
31
+ - Changed the use_to_json option to still allow as_json even when set to false.
32
32
 
33
- - Changed compat mode so that the :bigdecimal_as_decimal option over-rides the
34
- to_json method if the option is true. The default for mimic_JSON is to leave
35
- the option off.
36
-
37
- - Added support for Module encoding in compat mode.
38
-
39
- - Added ActiveSupportHelper so that require 'active_support_helper' will added
40
- a helper for serializing ActiveSupport::TimeWithZone.
41
-
42
- - Added float_precision option to control the number of digits used for floats
43
- when dumping.
44
-
45
- ### Release 2.10.4
46
-
47
- - Fixed Range encoding in compat mode to not use the object mode encoding.
48
-
49
- - Fixed serialization problem with timestamps.
50
-
51
- - Fixed compat parser to accept NaN and Infinity.
52
-
53
33
  [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
54
34
 
55
35
  ## Description
@@ -480,7 +480,7 @@ dump_float(VALUE obj, Out out) {
480
480
  volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
481
481
 
482
482
  cnt = RSTRING_LEN(rstr);
483
- if (sizeof(buf) <= cnt) {
483
+ if ((int)sizeof(buf) <= cnt) {
484
484
  cnt = sizeof(buf) - 1;
485
485
  }
486
486
  strncpy(buf, rb_string_value_ptr((VALUE*)&rstr), cnt);
@@ -1201,7 +1201,7 @@ dump_data_comp(VALUE obj, int depth, Out out) {
1201
1201
  volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
1202
1202
 
1203
1203
  dump_raw(rb_string_value_ptr((VALUE*)&rstr), RSTRING_LEN(rstr), out);
1204
- } else if (Yes == out->opts->to_json && rb_respond_to(obj, oj_as_json_id)) {
1204
+ } else if (rb_respond_to(obj, oj_as_json_id)) {
1205
1205
  volatile VALUE aj = rb_funcall(obj, oj_as_json_id, 0);
1206
1206
 
1207
1207
  // Catch the obvious brain damaged recursive dumping.
@@ -1298,7 +1298,7 @@ dump_obj_comp(VALUE obj, int depth, Out out) {
1298
1298
  rb_raise(rb_eTypeError, "%s.to_hash() did not return a Hash.\n", rb_class2name(rb_obj_class(obj)));
1299
1299
  }
1300
1300
  dump_hash(h, Qundef, depth, out->opts->mode, out);
1301
- } else if (Yes == out->opts->to_json && rb_respond_to(obj, oj_as_json_id)) {
1301
+ } else if (rb_respond_to(obj, oj_as_json_id)) {
1302
1302
  volatile VALUE aj = rb_funcall(obj, oj_as_json_id, 0);
1303
1303
 
1304
1304
  // Catch the obvious brain damaged recursive dumping.
@@ -1759,6 +1759,8 @@ dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
1759
1759
 
1760
1760
  if (sizeof(nbuf) <= nlen) {
1761
1761
  n2 = strdup(name);
1762
+ } else {
1763
+ strcpy(n2, name);
1762
1764
  }
1763
1765
  n = n2;
1764
1766
  v = obj;
@@ -380,7 +380,7 @@ set_def_opts(VALUE self, VALUE opts) {
380
380
  } else if (ascii_sym == v) {
381
381
  oj_default_options.escape_mode = ASCIIEsc;
382
382
  } else {
383
- rb_raise(rb_eArgError, ":encoding must be :json, :xss_safe, or :ascii.");
383
+ rb_raise(rb_eArgError, ":escape_mode must be :newline, :json, :xss_safe, or :ascii.");
384
384
  }
385
385
 
386
386
  v = rb_hash_lookup(opts, bigdecimal_load_sym);
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.11.0'
4
+ VERSION = '2.11.1'
5
5
  end
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+ %w(lib ext test).each do |dir|
6
+ $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
7
+ end
8
+
9
+ require 'minitest'
10
+ require 'minitest/autorun'
11
+
12
+ require 'sqlite3'
13
+ require 'active_record'
14
+ require 'oj'
15
+
16
+ #Oj.mimic_JSON()
17
+ Oj.default_options = {mode: :compat, indent: 2}
18
+
19
+ #ActiveRecord::Base.logger = Logger.new(STDERR)
20
+
21
+ ActiveRecord::Base.establish_connection(
22
+ :adapter => "sqlite3",
23
+ :database => ":memory:"
24
+ )
25
+
26
+ ActiveRecord::Schema.define do
27
+ create_table :users do |table|
28
+ table.column :first_name, :string
29
+ table.column :last_name, :string
30
+ table.column :email, :string
31
+ end
32
+ end
33
+
34
+ class User < ActiveRecord::Base
35
+ end
36
+
37
+ class ActiveTest < Minitest::Test
38
+
39
+ def test_active
40
+ User.find_or_create_by(first_name: "John", last_name: "Smith", email: "john@example.com")
41
+ User.find_or_create_by(first_name: "Joan", last_name: "Smith", email: "joan@example.com")
42
+
43
+ # Single instance.
44
+ assert_equal(%|{
45
+ "id":1,
46
+ "first_name":"John",
47
+ "last_name":"Smith",
48
+ "email":"john@example.com"
49
+ }
50
+ |, Oj.dump(User.first))
51
+
52
+ # Array of instances.
53
+ assert_equal(%|[
54
+ {
55
+ "id":1,
56
+ "first_name":"John",
57
+ "last_name":"Smith",
58
+ "email":"john@example.com"
59
+ },
60
+ {
61
+ "id":2,
62
+ "first_name":"Joan",
63
+ "last_name":"Smith",
64
+ "email":"joan@example.com"
65
+ }
66
+ ]
67
+ |, Oj.dump(User.all))
68
+
69
+ # Single instance as json. (not Oj)
70
+ assert_equal(%|{"id":1,"first_name":"John","last_name":"Smith","email":"john@example.com"}|, User.first.to_json)
71
+
72
+ # Array of instances as json. (not Oj)
73
+ assert_equal(%|[{"id":1,"first_name":"John","last_name":"Smith","email":"john@example.com"},{"id":2,"first_name":"Joan","last_name":"Smith","email":"joan@example.com"}]|, User.all.to_json)
74
+
75
+ end
76
+ end
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+ %w(lib ext test).each do |dir|
6
+ $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
7
+ end
8
+
9
+ require 'minitest'
10
+ require 'minitest/autorun'
11
+
12
+ require 'sqlite3'
13
+ require 'active_record'
14
+ require 'oj'
15
+
16
+ Oj.mimic_JSON()
17
+ Oj.default_options = {mode: :compat, indent: 2}
18
+
19
+ #ActiveRecord::Base.logger = Logger.new(STDERR)
20
+
21
+ ActiveRecord::Base.establish_connection(
22
+ :adapter => "sqlite3",
23
+ :database => ":memory:"
24
+ )
25
+
26
+ ActiveRecord::Schema.define do
27
+ create_table :users do |table|
28
+ table.column :first_name, :string
29
+ table.column :last_name, :string
30
+ table.column :email, :string
31
+ end
32
+ end
33
+
34
+ class User < ActiveRecord::Base
35
+ end
36
+
37
+ class ActiveTest < Minitest::Test
38
+
39
+ def test_active
40
+ User.find_or_create_by(first_name: "John", last_name: "Smith", email: "john@example.com")
41
+ User.find_or_create_by(first_name: "Joan", last_name: "Smith", email: "joan@example.com")
42
+
43
+ # Single instance.
44
+ assert_equal(%|{
45
+ "id":1,
46
+ "first_name":"John",
47
+ "last_name":"Smith",
48
+ "email":"john@example.com"
49
+ }
50
+ |, Oj.dump(User.first))
51
+
52
+ # Array of instances.
53
+ assert_equal(%|[
54
+ {
55
+ "id":1,
56
+ "first_name":"John",
57
+ "last_name":"Smith",
58
+ "email":"john@example.com"
59
+ },
60
+ {
61
+ "id":2,
62
+ "first_name":"Joan",
63
+ "last_name":"Smith",
64
+ "email":"joan@example.com"
65
+ }
66
+ ]
67
+ |, Oj.dump(User.all))
68
+
69
+ # Single instance as json. (not Oj)
70
+ assert_equal(%|{
71
+ "id":1,
72
+ "first_name":"John",
73
+ "last_name":"Smith",
74
+ "email":"john@example.com"
75
+ }
76
+ |, User.first.to_json)
77
+
78
+ # Array of instances as json. (not Oj)
79
+ assert_equal(%|[
80
+ {
81
+ "id":1,
82
+ "first_name":"John",
83
+ "last_name":"Smith",
84
+ "email":"john@example.com"
85
+ },
86
+ {
87
+ "id":2,
88
+ "first_name":"Joan",
89
+ "last_name":"Smith",
90
+ "email":"joan@example.com"
91
+ }
92
+ ]
93
+ |, User.all.to_json)
94
+
95
+ end
96
+ end
@@ -11,6 +11,7 @@ require 'active_model'
11
11
  require 'active_model_serializers'
12
12
  require 'active_support/json'
13
13
  require 'active_support/time'
14
+ require 'active_support/all'
14
15
 
15
16
  require 'oj/active_support_helper'
16
17
 
@@ -89,6 +90,26 @@ class MimicRails < Minitest::Test
89
90
  puts "*** serializer.as_json() #{serializer.as_json()}"
90
91
  json = JSON.dump(serializer)
91
92
  puts "*** JSON.dump(serializer) #{JSON.dump(serializer)}"
93
+
94
+ puts "*** category.to_json() #{category.to_json()}"
95
+ puts "*** category.as_json() #{category.as_json()}"
96
+ puts "*** JSON.dump(serializer) #{JSON.dump(category)}"
97
+ puts "*** Oj.dump(serializer) #{Oj.dump(category)}"
98
+
99
+ end
100
+
101
+ def test_dump_object_array
102
+ Oj.default_options= {:indent => 2}
103
+ cat1 = Category.new(1, 'test')
104
+ cat2 = Category.new(2, 'test')
105
+ a = Array.wrap([cat1, cat2])
106
+
107
+ #serializer = CategorySerializer.new(a)
108
+
109
+ puts "*** a.to_json() #{a.to_json()}"
110
+ puts "*** a.as_json() #{a.as_json()}"
111
+ puts "*** JSON.dump(a) #{JSON.dump(a)}"
112
+ puts "*** Oj.dump(a) #{Oj.dump(a)}"
92
113
  end
93
114
 
94
115
  def test_dump_time
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: 2.11.0
4
+ version: 2.11.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: 2014-11-02 00:00:00.000000000 Z
11
+ date: 2014-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -101,6 +101,8 @@ files:
101
101
  - lib/oj/saj.rb
102
102
  - lib/oj/schandler.rb
103
103
  - lib/oj/version.rb
104
+ - test/_test_active.rb
105
+ - test/_test_active_mimic.rb
104
106
  - test/_test_mimic_rails.rb
105
107
  - test/bug.rb
106
108
  - test/bug2.rb