oj 2.10.2 → 2.10.3

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: 8a212c2204a5f29bb42b42ed9db56d51f44bda08
4
- data.tar.gz: 6f151a8f68ff8720ebb3e1dac263b234d0cedb00
3
+ metadata.gz: 305f46dd63f131a124b3716a4d884f5dc355b80e
4
+ data.tar.gz: bcb452a3c8ca23658bd5f3362434fdb57c2fc5c8
5
5
  SHA512:
6
- metadata.gz: 94d89b9109d22a280a368caf064717a7f662e9056681c1ec8ac6aae6d9c775cf5ef3cad6619cd3610d5864f0ad3f3d785c2aebf862a5891a027ce2180e588fa5
7
- data.tar.gz: bee25237960557655787c3082aaf56652bcf002d0da6b23445bd30549a895be177215a266e5133dad8946d5dea8b83662dede24570623c3cf193fb3d626fffd0
6
+ metadata.gz: 8c52c779973b9e6af3d5cfcd32236070a431fd16e79f204737179e00025c66c212c934c68e8a9d3c1a4838f1d9239c210ed85efe10996fd19baf63736d1a7550
7
+ data.tar.gz: ea85ed66665d3c10cb8b2ae96d014530cae2bed32bd1c1168a1b4e8c96308827f5032d78f5ced787aa225b9f72b1558ecc5f4282fa47ee47593919b7833cb5ff
data/README.md CHANGED
@@ -26,9 +26,14 @@ 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.10.2
29
+ ### Current Release 2.10.3
30
30
 
31
- - Fixed string corruption bug due to an uncommented assignment used for debugging.
31
+ - Using the xmlschema option with :object mode now saves time as a string and
32
+ preserves the timezone.
33
+
34
+ - Rational recursive loop caused by active support fixed.
35
+
36
+ - Time in mimic_JSON mode are now the ruby string representation of a date.
32
37
 
33
38
  [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
34
39
 
@@ -54,7 +59,7 @@ is the `:object` mode.
54
59
  performance mode.
55
60
 
56
61
  - `:compat` mode attempts to be compatible with other systems. It will serialize any
57
- `Object`, but will check to see if the `Object` implements an `as_hash` or `to_json`
62
+ `Object`, but will check to see if the `Object` implements an `to_hash` or `to_json`
58
63
  method. If either exists, that method is used for serializing the `Object`.
59
64
  Since `as_json` is more flexible and produces more consistent output, it is
60
65
  preferred over the `to_json` method. If neither the `to_json` or `to_hash`
@@ -997,15 +997,13 @@ dump_time(VALUE obj, Out out) {
997
997
  long nsec = NUM2LONG(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
998
998
  #endif
999
999
  #endif
1000
-
1000
+
1001
1001
  if (0 > sec) {
1002
1002
  neg = 1;
1003
1003
  sec = -sec;
1004
1004
  if (0 < nsec) {
1005
1005
  nsec = 1000000000 - nsec;
1006
- #ifndef JRUBY_RUBY
1007
1006
  sec--;
1008
- #endif
1009
1007
  }
1010
1008
  }
1011
1009
  *b-- = '\0';
@@ -1237,7 +1235,16 @@ dump_data_obj(VALUE obj, int depth, Out out) {
1237
1235
  *out->cur++ = 't';
1238
1236
  *out->cur++ = '"';
1239
1237
  *out->cur++ = ':';
1240
- dump_time(obj, out);
1238
+ switch (out->opts->time_format) {
1239
+ case RubyTime: // Does not output fractional seconds
1240
+ case XmlTime:
1241
+ dump_xml_time(obj, out);
1242
+ break;
1243
+ case UnixTime:
1244
+ default:
1245
+ dump_time(obj, out);
1246
+ break;
1247
+ }
1241
1248
  *out->cur++ = '}';
1242
1249
  *out->cur = '\0';
1243
1250
  } else {
@@ -1264,7 +1271,7 @@ dump_obj_comp(VALUE obj, int depth, Out out) {
1264
1271
  rb_raise(rb_eTypeError, "%s.to_hash() did not return a Hash.\n", rb_class2name(rb_obj_class(obj)));
1265
1272
  }
1266
1273
  dump_hash(h, Qundef, depth, out->opts->mode, out);
1267
- } else if (rb_respond_to(obj, oj_as_json_id)) {
1274
+ } else if (Yes == out->opts->to_json && rb_respond_to(obj, oj_as_json_id)) {
1268
1275
  dump_val(rb_funcall(obj, oj_as_json_id, 0), depth, out);
1269
1276
  } else if (Yes == out->opts->to_json && rb_respond_to(obj, oj_to_json_id)) {
1270
1277
  volatile VALUE rs;
@@ -1292,7 +1299,11 @@ dump_obj_comp(VALUE obj, int depth, Out out) {
1292
1299
  } else {
1293
1300
  dump_cstr(rb_string_value_ptr((VALUE*)&rstr), RSTRING_LEN(rstr), 0, 0, out);
1294
1301
  }
1302
+ #if (defined T_RATIONAL && defined RRATIONAL)
1303
+ } else if (oj_datetime_class == clas || oj_date_class == clas || rb_cRational == clas) {
1304
+ #else
1295
1305
  } else if (oj_datetime_class == clas || oj_date_class == clas) {
1306
+ #endif
1296
1307
  volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
1297
1308
 
1298
1309
  dump_cstr(rb_string_value_ptr((VALUE*)&rstr), RSTRING_LEN(rstr), 0, 0, out);
@@ -132,6 +132,9 @@ hat_cstr(ParseInfo pi, Val parent, Val kval, const char *str, size_t len) {
132
132
  case 'c': // class
133
133
  parent->val = oj_name2class(pi, str, len, Yes == pi->options.auto_define);
134
134
  break;
135
+ case 't': // time
136
+ parent->val = rb_funcall(oj_time_class, rb_intern("parse"), 1, rb_str_new(str, len));
137
+ break;
135
138
  default:
136
139
  return 0;
137
140
  break;
@@ -161,6 +164,9 @@ hat_num(ParseInfo pi, Val parent, Val kval, NumInfo ni) {
161
164
  #else
162
165
  parent->val = rb_time_new(ni->i, (long)(nsec / 1000));
163
166
  #endif
167
+ // TBD if there is an exponent then if not gmt_offset
168
+ // add gmt_offset and then getgmt()
169
+ // if not 0 then getlocal(offset)
164
170
  }
165
171
  break;
166
172
  case 'i': // circular index
@@ -1716,7 +1716,7 @@ static struct _Options mimic_object_to_json_options = {
1716
1716
  JSONEsc, // escape_mode
1717
1717
  CompatMode, // mode
1718
1718
  No, // class_cache
1719
- UnixTime, // time_format
1719
+ RubyTime, // time_format
1720
1720
  Yes, // bigdec_as_num
1721
1721
  AutoDec, // bigdec_load
1722
1722
  No, // to_json
@@ -1738,7 +1738,8 @@ mimic_object_to_json(int argc, VALUE *argv, VALUE self) {
1738
1738
  out.buf = buf;
1739
1739
  out.end = buf + sizeof(buf) - 10;
1740
1740
  out.allocated = 0;
1741
- oj_dump_obj_to_json(self, &mimic_object_to_json_options, &out);
1741
+ //oj_dump_obj_to_json(self, &mimic_object_to_json_options, &out);
1742
+ oj_dump_obj_to_json(self, &oj_default_options, &out);
1742
1743
  if (0 == out.buf) {
1743
1744
  rb_raise(rb_eNoMemError, "Not enough memory.");
1744
1745
  }
@@ -1844,9 +1845,7 @@ define_mimic_json(int argc, VALUE *argv, VALUE self) {
1844
1845
  rb_define_class_under(mimic, "State", rb_cObject);
1845
1846
  }
1846
1847
 
1847
- oj_default_options.mode = CompatMode;
1848
- oj_default_options.escape_mode = ASCIIEsc;
1849
- oj_default_options.nilnil = Yes;
1848
+ oj_default_options = mimic_object_to_json_options;
1850
1849
 
1851
1850
  return mimic;
1852
1851
  }
@@ -1880,6 +1879,7 @@ iconv_rescue(VALUE x) {
1880
1879
 
1881
1880
  static VALUE
1882
1881
  protect_require(VALUE x) {
1882
+ rb_require("time");
1883
1883
  rb_require("bigdecimal");
1884
1884
  return Qnil;
1885
1885
  }
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.10.2'
4
+ VERSION = '2.10.3'
5
5
  end
@@ -1,5 +1,8 @@
1
+ #!/usr/bin/env ruby
1
2
  # encoding: UTF-8
2
3
 
4
+ $: << File.dirname(__FILE__)
5
+
3
6
  require 'helper'
4
7
  Oj.mimic_JSON
5
8
  require 'rails/all'
@@ -25,6 +28,17 @@ class MimicRails < Minitest::Test
25
28
  true,
26
29
  null
27
30
  ]
31
+ }, json)
32
+ end
33
+
34
+ def test_dump_rational
35
+ Oj.default_options= {:indent => 2} # JSON this will not change anything
36
+ json = ActiveSupport::JSON.encode([1, true, Rational(1)])
37
+ assert_equal(%{[
38
+ 1,
39
+ true,
40
+ "1/1"
41
+ ]
28
42
  }, json)
29
43
  end
30
44
 
@@ -186,7 +186,7 @@ class SharedMimicTest < Minitest::Test
186
186
  end
187
187
  def test_parse_additions
188
188
  jam = Jam.new(true, 58)
189
- json = Oj.dump(jam, :mode => :compat)
189
+ json = Oj.dump(jam, :mode => :compat, :use_to_json => true)
190
190
  obj = JSON.parse(json)
191
191
  assert_equal(jam, obj)
192
192
  obj = JSON.parse(json, :create_additions => true)
@@ -209,7 +209,7 @@ class SharedMimicTest < Minitest::Test
209
209
  def test_recurse_proc
210
210
  children = []
211
211
  JSON.recurse_proc({ 'a' => 1, 'b' => [true, false]}) { |x| children << x }
212
- # JRuby 1.7.0 rb_yield() is broken and converts the [true, falser] array into true
212
+ # JRuby 1.7.0 rb_yield() is broken and converts the [true, false] array into true
213
213
  unless 'jruby' == $ruby && '1.9.3' == RUBY_VERSION
214
214
  assert([1, true, false, [true, false], { 'a' => 1, 'b' => [true, false]}] == children ||
215
215
  [true, false, [true, false], 1, { 'b' => [true, false], 'a' => 1}] == children)
@@ -269,6 +269,7 @@ class CompatJuice < Minitest::Test
269
269
 
270
270
  def test_json_object_compat
271
271
  obj = Jeez.new(true, 58)
272
+ Oj.default_options = { :mode => :compat, :use_to_json => true }
272
273
  dump_and_load(obj, false)
273
274
  end
274
275
 
@@ -279,7 +280,7 @@ class CompatJuice < Minitest::Test
279
280
 
280
281
  def test_json_object_create_id
281
282
  expected = Jeez.new(true, 58)
282
- json = Oj.dump(expected, :indent => 2, :mode => :compat)
283
+ json = Oj.dump(expected, :indent => 2, :mode => :compat, :use_to_json => true)
283
284
  obj = Oj.compat_load(json)
284
285
  assert_equal(expected, obj)
285
286
  end
@@ -297,7 +298,7 @@ class CompatJuice < Minitest::Test
297
298
 
298
299
  def test_json_object_create_cache
299
300
  expected = Jeez.new(true, 58)
300
- json = Oj.dump(expected, :indent => 2, :mode => :compat)
301
+ json = Oj.dump(expected, :indent => 2, :mode => :compat, :use_to_json => true)
301
302
  obj = Oj.compat_load(json, :class_cache => true)
302
303
  assert_equal(expected, obj)
303
304
  obj = Oj.compat_load(json, :class_cache => false)
@@ -306,7 +307,7 @@ class CompatJuice < Minitest::Test
306
307
 
307
308
  def test_json_object_create_id_other
308
309
  expected = Jeez.new(true, 58)
309
- json = Oj.dump(expected, :indent => 2, :mode => :compat)
310
+ json = Oj.dump(expected, :indent => 2, :mode => :compat, :use_to_json => true)
310
311
  json.gsub!('json_class', '_class_')
311
312
  obj = Oj.compat_load(json, :create_id => "_class_")
312
313
  assert_equal(expected, obj)
@@ -36,7 +36,7 @@ class DebJuice < Minitest::Test
36
36
  end
37
37
 
38
38
  def test_as_json_object_compat_hash_cached
39
- Oj.default_options = { :mode => :compat, :class_cache => true }
39
+ Oj.default_options = { :mode => :compat, :class_cache => true, :use_to_json => true }
40
40
  obj = Orange.new(true, 58)
41
41
  json = Oj.dump(obj, :indent => 2)
42
42
  assert(!json.nil?)
@@ -79,7 +79,7 @@ class FileJuice < Minitest::Test
79
79
  end
80
80
 
81
81
  def test_float
82
- mode = opts = Oj.default_options()[:mode]
82
+ mode = Oj.default_options()[:mode]
83
83
  Oj.default_options = {:mode => :object}
84
84
  dump_and_load(0.0, false)
85
85
  dump_and_load(12345.6789, false)
@@ -157,7 +157,7 @@ class FileJuice < Minitest::Test
157
157
  end
158
158
 
159
159
  def test_as_json_object_compat_hash
160
- Oj.default_options = { :mode => :compat }
160
+ Oj.default_options = { :mode => :compat, :use_to_json => true }
161
161
  obj = Orange.new(true, 58)
162
162
  json = Oj.dump(obj, :indent => 2)
163
163
  assert(!json.nil?)
@@ -355,6 +355,24 @@ class ObjectJuice < Minitest::Test
355
355
  dump_and_load(t, false)
356
356
  end
357
357
 
358
+ def test_xml_time
359
+ Oj.default_options = { :mode => :object, :time_format => :xmlschema }
360
+ t = Time.now()
361
+ dump_and_load(t, false)
362
+ end
363
+
364
+ def test_utc_time
365
+ Oj.default_options = { :mode => :object, :time_format => :xmlschema }
366
+ t = Time.now().utc
367
+ dump_and_load(t, false)
368
+ end
369
+
370
+ def test_ruby_time
371
+ Oj.default_options = { :mode => :object, :time_format => :ruby }
372
+ t = Time.now()
373
+ dump_and_load(t, false)
374
+ end
375
+
358
376
  def test_time_early
359
377
  t = Time.xmlschema("1954-01-05T00:00:00.123456")
360
378
  dump_and_load(t, false)
@@ -167,7 +167,7 @@ class Juice < Minitest::Test
167
167
  end
168
168
 
169
169
  def test_float
170
- mode = opts = Oj.default_options()[:mode]
170
+ mode = Oj.default_options()[:mode]
171
171
  Oj.default_options = {:mode => :object}
172
172
  dump_and_load(0.0, false)
173
173
  dump_and_load(12345.6789, false)
@@ -398,7 +398,11 @@ class Juice < Minitest::Test
398
398
  sign = '-'
399
399
  tz = -tz
400
400
  end
401
- assert_equal(%{"2012-01-05T23:58:07%s%02d:%02d"} % [sign, tz / 3600, tz / 60 % 60], json)
401
+ if RUBY_VERSION.start_with?('1.8')
402
+ assert_equal(%{"2012-01-05T23:58:07%sZ"} % [sign], json)
403
+ else
404
+ assert_equal(%{"2012-01-05T23:58:07%s%02d:%02d"} % [sign, tz / 3600, tz / 60 % 60], json)
405
+ end
402
406
  end
403
407
  end
404
408
  def test_xml_time_compat_precision
@@ -436,7 +440,11 @@ class Juice < Minitest::Test
436
440
  sign = '-'
437
441
  tz = -tz
438
442
  end
439
- assert_equal(%{"2012-01-05T23:58:08%s%02d:%02d"} % [sign, tz / 3600, tz / 60 % 60], json)
443
+ if RUBY_VERSION.start_with?('1.8')
444
+ assert_equal(%{"2012-01-05T23:58:08%sZ"} % [sign], json)
445
+ else
446
+ assert_equal(%{"2012-01-05T23:58:08%s%02d:%02d"} % [sign, tz / 3600, tz / 60 % 60], json)
447
+ end
440
448
  end
441
449
  end
442
450
  def test_xml_time_compat_zulu
@@ -656,7 +664,7 @@ class Juice < Minitest::Test
656
664
  end
657
665
 
658
666
  def test_as_json_object_compat_hash
659
- Oj.default_options = { :mode => :compat }
667
+ Oj.default_options = { :mode => :compat, :use_to_json => true }
660
668
  obj = Orange.new(true, 58)
661
669
  json = Oj.dump(obj, :indent => 2)
662
670
  assert(!json.nil?)
@@ -664,7 +672,7 @@ class Juice < Minitest::Test
664
672
  end
665
673
 
666
674
  def test_as_json_object_compat_non_hash
667
- Oj.default_options = { :mode => :compat }
675
+ Oj.default_options = { :mode => :compat, :use_to_json => true }
668
676
  obj = Melon.new(true, 58)
669
677
  json = Oj.dump(obj, :indent => 2)
670
678
  assert_equal(%{"true 58"}, json)
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.10.2
4
+ version: 2.10.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: 2014-08-20 00:00:00.000000000 Z
11
+ date: 2014-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler