oj 1.4.1 → 1.4.2

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.

Files changed (5) hide show
  1. data/README.md +6 -0
  2. data/ext/oj/dump.c +46 -7
  3. data/lib/oj/version.rb +1 -1
  4. data/test/tests.rb +13 -14
  5. metadata +1 -1
data/README.md CHANGED
@@ -32,6 +32,12 @@ A fast JSON parser and Object marshaller as a Ruby gem.
32
32
 
33
33
  ## <a name="release">Release Notes</a>
34
34
 
35
+ ### Release 1.4.2
36
+
37
+ - Fixed dump and load of BigDecimals in :object mode.
38
+
39
+ - BigDecimals are now dumped and loaded in all modes.
40
+
35
41
  ### Release 1.4.1
36
42
 
37
43
  - Windows RubyInstaller and TCS-Ruby now supported thanks to Jarmo Pertman. Thanks Jarmo.
@@ -91,6 +91,8 @@ static void dump_hash(VALUE obj, int depth, int mode, Out out);
91
91
  static void dump_time(VALUE obj, Out out);
92
92
  static void dump_ruby_time(VALUE obj, Out out);
93
93
  static void dump_xml_time(VALUE obj, Out out);
94
+ static void dump_data_strict(VALUE obj, Out out);
95
+ static void dump_data_null(VALUE obj, Out out);
94
96
  static void dump_data_comp(VALUE obj, Out out);
95
97
  static void dump_data_obj(VALUE obj, int depth, Out out);
96
98
  static void dump_obj_comp(VALUE obj, int depth, Out out);
@@ -1029,6 +1031,32 @@ dump_xml_time(VALUE obj, Out out) {
1029
1031
  }
1030
1032
  }
1031
1033
 
1034
+ static void
1035
+ dump_data_strict(VALUE obj, Out out) {
1036
+ VALUE clas = rb_obj_class(obj);
1037
+
1038
+ if (oj_bigdecimal_class == clas) {
1039
+ VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
1040
+
1041
+ dump_raw(StringValuePtr(rstr), RSTRING_LEN(rstr), out);
1042
+ } else {
1043
+ raise_strict(obj);
1044
+ }
1045
+ }
1046
+
1047
+ static void
1048
+ dump_data_null(VALUE obj, Out out) {
1049
+ VALUE clas = rb_obj_class(obj);
1050
+
1051
+ if (oj_bigdecimal_class == clas) {
1052
+ VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
1053
+
1054
+ dump_raw(StringValuePtr(rstr), RSTRING_LEN(rstr), out);
1055
+ } else {
1056
+ dump_nil(out);
1057
+ }
1058
+ }
1059
+
1032
1060
  static void
1033
1061
  dump_data_comp(VALUE obj, Out out) {
1034
1062
  VALUE clas = rb_obj_class(obj);
@@ -1072,11 +1100,16 @@ dump_data_obj(VALUE obj, int depth, Out out) {
1072
1100
  *out->cur++ = '}';
1073
1101
  *out->cur = '\0';
1074
1102
  } else {
1075
- VALUE clas = rb_obj_class(obj);
1076
1103
  Odd odd = oj_get_odd(clas);
1077
1104
 
1078
1105
  if (0 == odd) {
1079
- dump_nil(out);
1106
+ if (oj_bigdecimal_class == clas) {
1107
+ VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
1108
+
1109
+ dump_raw(StringValuePtr(rstr), RSTRING_LEN(rstr), out);
1110
+ } else {
1111
+ dump_nil(out);
1112
+ }
1080
1113
  } else {
1081
1114
  dump_odd(obj, odd, clas, depth + 1, out);
1082
1115
  }
@@ -1133,7 +1166,13 @@ dump_obj_obj(VALUE obj, int depth, Out out) {
1133
1166
  Odd odd = oj_get_odd(clas);
1134
1167
 
1135
1168
  if (0 == odd) {
1136
- dump_obj_attrs(obj, clas, id, depth, out);
1169
+ if (oj_bigdecimal_class == clas) {
1170
+ VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
1171
+
1172
+ dump_raw(StringValuePtr(rstr), RSTRING_LEN(rstr), out);
1173
+ } else {
1174
+ dump_obj_attrs(obj, clas, id, depth, out);
1175
+ }
1137
1176
  } else {
1138
1177
  dump_odd(obj, odd, clas, depth + 1, out);
1139
1178
  }
@@ -1469,8 +1508,8 @@ dump_val(VALUE obj, int depth, Out out) {
1469
1508
  #endif
1470
1509
  case T_OBJECT:
1471
1510
  switch (out->opts->mode) {
1472
- case StrictMode: raise_strict(obj); break;
1473
- case NullMode: dump_nil(out); break;
1511
+ case StrictMode: dump_data_strict(obj, out); break;
1512
+ case NullMode: dump_data_null(obj, out); break;
1474
1513
  case CompatMode: dump_obj_comp(obj, depth, out); break;
1475
1514
  case ObjectMode:
1476
1515
  default: dump_obj_obj(obj, depth, out); break;
@@ -1478,8 +1517,8 @@ dump_val(VALUE obj, int depth, Out out) {
1478
1517
  break;
1479
1518
  case T_DATA:
1480
1519
  switch (out->opts->mode) {
1481
- case StrictMode: raise_strict(obj); break;
1482
- case NullMode: dump_nil(out); break;
1520
+ case StrictMode: dump_data_strict(obj, out); break;
1521
+ case NullMode: dump_data_null(obj, out); break;
1483
1522
  case CompatMode: dump_data_comp(obj, out); break;
1484
1523
  case ObjectMode:
1485
1524
  default: dump_data_obj(obj, depth, out); break;
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '1.4.1'
4
+ VERSION = '1.4.2'
5
5
  end
@@ -162,10 +162,6 @@ class Juice < ::Test::Unit::TestCase
162
162
  dump_and_load(1, false)
163
163
  end
164
164
 
165
- def test_bignum
166
- dump_and_load(12345678901234567890123456789, false)
167
- end
168
-
169
165
  def test_float
170
166
  dump_and_load(0.0, false)
171
167
  dump_and_load(12345.6789, false)
@@ -649,16 +645,16 @@ class Juice < ::Test::Unit::TestCase
649
645
 
650
646
  # BigDecimal
651
647
  def test_bigdecimal_strict
652
- begin
653
- json = Oj.dump(BigDecimal.new('3.14159265358979323846'), :mode => :strict)
654
- assert(false)
655
- rescue Exception => e
656
- assert(true)
657
- end
648
+ mode = Oj.default_options[:mode]
649
+ Oj.default_options = {:mode => :strict}
650
+ dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
651
+ Oj.default_options = {:mode => mode}
658
652
  end
659
653
  def test_bigdecimal_null
660
- json = Oj.dump(BigDecimal.new('3.14159265358979323846'), :mode => :null)
661
- assert_equal('null', json)
654
+ mode = Oj.default_options[:mode]
655
+ Oj.default_options = {:mode => :null}
656
+ dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
657
+ Oj.default_options = {:mode => mode}
662
658
  end
663
659
  def test_bigdecimal_compat
664
660
  orig = BigDecimal.new('3.14159265358979323846')
@@ -667,11 +663,14 @@ class Juice < ::Test::Unit::TestCase
667
663
  assert_equal(orig, bg)
668
664
  end
669
665
  def test_bigdecimal_object
666
+ mode = Oj.default_options[:mode]
667
+ Oj.default_options = {:mode => :object}
670
668
  dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
669
+ Oj.default_options = {:mode => mode}
671
670
  # Infinity is the same for Float and BigDecimal
672
- json = Oj.dump(BigDecimal.new('Infinity'), :mode => :compat)
671
+ json = Oj.dump(BigDecimal.new('Infinity'), :mode => :object)
673
672
  assert_equal('Infinity', json)
674
- json = Oj.dump(BigDecimal.new('-Infinity'), :mode => :compat)
673
+ json = Oj.dump(BigDecimal.new('-Infinity'), :mode => :object)
675
674
  assert_equal('-Infinity', json)
676
675
  end
677
676
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: