oj 2.14.4 → 2.14.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
  SHA1:
3
- metadata.gz: e24cfa368da8658a1a0d7a327081d3dcf54eb2b1
4
- data.tar.gz: c54d265f263e0e5ff7fe5694b7318b6ec25dc594
3
+ metadata.gz: 18d01b3bb2476564f6b39dd5df0b8ece9d9dd2a4
4
+ data.tar.gz: b1927b77d0fad77544118e3d11a137374cf1630d
5
5
  SHA512:
6
- metadata.gz: cb94917cf00f55f316fa6679ff46f01a7bbfc8fb8e6c162db4c28fb35bf9c102f8ed37360672b2a5ca5b07f61b0e33bb3419f0a4736bef09ed3455a89fe5a8d5
7
- data.tar.gz: 49dee1f8813f27c8b846b1a81c2e4ac0ca97579f3a2ccd1bc1175f3ed6eb51684d304dc76137c12266ba884cc316a47a909b509ee1d01d0c892410ae7cad339c
6
+ metadata.gz: 2a493651cc5bffc96ec16a7cbb98e8d025a2484419ccad9ea67a0fd9f854eaf7f26efaf7f5740988e01c63426a424571f2d65ef2d07dc29128ec1c6ed41eb066
7
+ data.tar.gz: 89e15826b019ddc6a70b9c8c130edb26f44afdf0115e603d3b45a47a20105b78530a46740630595272bd89771a95439f6614ff6c5e7e44b0ce1eb75eb7b57f51
data/README.md CHANGED
@@ -69,7 +69,7 @@ actual default options but on a copy of the Hash:
69
69
  Oj.default_options = {:mode => :compat }
70
70
  ```
71
71
 
72
- * `:mode` [Symbol] mode for dumping and loading JSON.
72
+ * `:mode` [Symbol] mode for dumping and loading JSON. **Important format details [here](http://www.ohler.com/dev/oj_misc/encoding_format.html).**
73
73
 
74
74
  - `:object` mode will dump any `Object` as a JSON `Object` with keys that
75
75
  match the Ruby `Object`'s variable names without the '@' prefix
@@ -159,9 +159,10 @@ Oj.default_options = {:mode => :compat }
159
159
 
160
160
  ## Releases
161
161
 
162
- **Release 2.14.4**
162
+ **Release 2.14.5**
163
163
 
164
- - When not in quirks mode strings are now raise an exception if they are the top level JSON value.
164
+ - Parse errors in mimic mode are not a separate class than Oj.ParseError so the
165
+ displayed name is JSON::ParserError instead.
165
166
 
166
167
  [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
167
168
 
@@ -130,6 +130,7 @@ oj_compat_parse(int argc, VALUE *argv, VALUE self) {
130
130
 
131
131
  pi.options = oj_default_options;
132
132
  pi.handler = Qnil;
133
+ pi.err_class = Qnil;
133
134
  oj_set_compat_callbacks(&pi);
134
135
 
135
136
  if (T_STRING == rb_type(*argv)) {
@@ -145,6 +146,7 @@ oj_compat_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
145
146
 
146
147
  pi.options = oj_default_options;
147
148
  pi.handler = Qnil;
149
+ pi.err_class = Qnil;
148
150
  oj_set_strict_callbacks(&pi);
149
151
  pi.end_hash = end_hash;
150
152
  pi.hash_set_cstr = hash_set_cstr;
@@ -776,6 +776,7 @@ oj_object_parse(int argc, VALUE *argv, VALUE self) {
776
776
 
777
777
  pi.options = oj_default_options;
778
778
  pi.handler = Qnil;
779
+ pi.err_class = Qnil;
779
780
  oj_set_object_callbacks(&pi);
780
781
 
781
782
  if (T_STRING == rb_type(*argv)) {
@@ -791,6 +792,7 @@ oj_object_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
791
792
 
792
793
  pi.options = oj_default_options;
793
794
  pi.handler = Qnil;
795
+ pi.err_class = Qnil;
794
796
  oj_set_strict_callbacks(&pi);
795
797
  pi.end_hash = end_hash;
796
798
  pi.start_hash = start_hash;
@@ -122,6 +122,7 @@ static VALUE float_prec_sym;
122
122
  static VALUE float_sym;
123
123
  static VALUE indent_sym;
124
124
  static VALUE json_sym;
125
+ static VALUE json_parser_error_class;
125
126
  static VALUE mode_sym;
126
127
  static VALUE newline_sym;
127
128
  static VALUE nilnil_sym;
@@ -752,6 +753,7 @@ load_file(int argc, VALUE *argv, VALUE self) {
752
753
  Check_Type(*argv, T_STRING);
753
754
  pi.options = oj_default_options;
754
755
  pi.handler = Qnil;
756
+ pi.err_class = Qnil;
755
757
  if (2 <= argc) {
756
758
  VALUE ropts = argv[1];
757
759
  VALUE v;
@@ -806,6 +808,7 @@ safe_load(VALUE self, VALUE doc) {
806
808
  struct _ParseInfo pi;
807
809
  VALUE args[1];
808
810
 
811
+ pi.err_class = Qnil;
809
812
  pi.options = oj_default_options;
810
813
  pi.options.auto_define = No;
811
814
  pi.options.sym_key = No;
@@ -1591,6 +1594,7 @@ mimic_load(int argc, VALUE *argv, VALUE self) {
1591
1594
  VALUE obj;
1592
1595
  VALUE p = Qnil;
1593
1596
 
1597
+ pi.err_class = json_parser_error_class;
1594
1598
  pi.options = oj_default_options;
1595
1599
  oj_set_compat_callbacks(&pi);
1596
1600
 
@@ -1727,6 +1731,7 @@ mimic_parse(int argc, VALUE *argv, VALUE self) {
1727
1731
  rb_raise(rb_eArgError, "Wrong number of arguments to parse.");
1728
1732
  }
1729
1733
  oj_set_compat_callbacks(&pi);
1734
+ pi.err_class = json_parser_error_class;
1730
1735
  pi.options = oj_default_options;
1731
1736
  pi.options.auto_define = No;
1732
1737
  pi.options.quirks_mode = No;
@@ -1942,7 +1947,8 @@ define_mimic_json(int argc, VALUE *argv, VALUE self) {
1942
1947
  if (rb_const_defined_at(mimic, rb_intern("ParserError"))) {
1943
1948
  rb_funcall(mimic, rb_intern("remove_const"), 1, ID2SYM(rb_intern("ParserError")));
1944
1949
  }
1945
- rb_define_const(mimic, "ParserError", oj_parse_error_class);
1950
+ rb_define_class_under(mimic, "ParserError", rb_eException);
1951
+ json_parser_error_class = rb_const_get(mimic, rb_intern("ParserError"));
1946
1952
 
1947
1953
  if (!rb_const_defined_at(mimic, rb_intern("State"))) {
1948
1954
  rb_define_class_under(mimic, "State", rb_cObject);
@@ -2107,6 +2113,7 @@ void Init_oj() {
2107
2113
  oj_parse_error_class = rb_const_get_at(Oj, rb_intern("ParseError"));
2108
2114
  oj_stringio_class = rb_const_get(rb_cObject, rb_intern("StringIO"));
2109
2115
  oj_struct_class = rb_const_get(rb_cObject, rb_intern("Struct"));
2116
+ json_parser_error_class = Qnil; // replaced if mimic is called
2110
2117
 
2111
2118
  allow_gc_sym = ID2SYM(rb_intern("allow_gc")); rb_gc_register_address(&allow_gc_sym);
2112
2119
  ascii_only_sym = ID2SYM(rb_intern("ascii_only")); rb_gc_register_address(&ascii_only_sym);
@@ -906,23 +906,35 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
906
906
  rb_jump_tag(line);
907
907
  }
908
908
  if (err_has(&pi->err)) {
909
+ if (Qnil != pi->err_class) {
910
+ pi->err.clas = pi->err_class;
911
+ }
909
912
  oj_err_raise(&pi->err);
910
913
  }
911
914
  if (pi->options.quirks_mode == No) {
912
915
  switch (rb_type(result)) {
913
- case T_NIL:
914
- case T_TRUE:
915
- case T_FALSE:
916
- case T_FIXNUM:
917
- case T_FLOAT:
918
- case T_CLASS:
919
- case T_STRING:
920
- case T_SYMBOL:
921
- rb_raise(oj_parse_error_class, "unexpected non-document value");
922
- break;
923
- default:
924
- // okay
925
- break;
916
+ case T_NIL:
917
+ case T_TRUE:
918
+ case T_FALSE:
919
+ case T_FIXNUM:
920
+ case T_FLOAT:
921
+ case T_CLASS:
922
+ case T_STRING:
923
+ case T_SYMBOL: {
924
+ struct _Err err;
925
+
926
+ if (Qnil == pi->err_class) {
927
+ err.clas = oj_parse_error_class;
928
+ } else {
929
+ err.clas = pi->err_class;
930
+ }
931
+ snprintf(err.msg, sizeof(err.msg), "unexpected non-document value");
932
+ oj_err_raise(&err);
933
+ break;
934
+ }
935
+ default:
936
+ // okay
937
+ break;
926
938
  }
927
939
  }
928
940
  return result;
@@ -88,6 +88,7 @@ typedef struct _ParseInfo {
88
88
  void (*add_cstr)(struct _ParseInfo *pi, const char *str, size_t len, const char *orig);
89
89
  void (*add_num)(struct _ParseInfo *pi, NumInfo ni);
90
90
  void (*add_value)(struct _ParseInfo *pi, VALUE val);
91
+ VALUE err_class;
91
92
  } *ParseInfo;
92
93
 
93
94
  extern void oj_parse2(ParseInfo pi);
@@ -187,6 +187,7 @@ oj_sc_parse(int argc, VALUE *argv, VALUE self) {
187
187
  struct _ParseInfo pi;
188
188
  VALUE input = argv[1];
189
189
 
190
+ pi.err_class = Qnil;
190
191
  pi.options = oj_default_options;
191
192
  if (3 == argc) {
192
193
  oj_parse_options(argv[2], &pi.options);
@@ -809,6 +809,9 @@ oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd) {
809
809
  rb_jump_tag(line);
810
810
  }
811
811
  if (err_has(&pi->err)) {
812
+ if (Qnil != pi->err_class) {
813
+ pi->err.clas = pi->err_class;
814
+ }
812
815
  oj_err_raise(&pi->err);
813
816
  }
814
817
  return result;
@@ -159,6 +159,7 @@ oj_strict_parse(int argc, VALUE *argv, VALUE self) {
159
159
 
160
160
  pi.options = oj_default_options;
161
161
  pi.handler = Qnil;
162
+ pi.err_class = Qnil;
162
163
  oj_set_strict_callbacks(&pi);
163
164
 
164
165
  if (T_STRING == rb_type(*argv)) {
@@ -174,6 +175,7 @@ oj_strict_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
174
175
 
175
176
  pi.options = oj_default_options;
176
177
  pi.handler = Qnil;
178
+ pi.err_class = Qnil;
177
179
  oj_set_strict_callbacks(&pi);
178
180
 
179
181
  return oj_pi_parse(argc, argv, &pi, json, len, 1);
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.14.4'
4
+ VERSION = '2.14.5'
5
5
  end
@@ -68,7 +68,7 @@ $obj = {
68
68
  Oj.default_options = { :indent => $indent, :mode => :compat }
69
69
 
70
70
  if 0 < $size
71
- s = Oj.dump($obj, :mode => :compat).size + 1
71
+ s = Oj.dump($obj).size + 1
72
72
  cnt = $size * 1024 / s
73
73
  o = $obj
74
74
  $obj = []
@@ -77,7 +77,7 @@ if 0 < $size
77
77
  end
78
78
  end
79
79
 
80
- $json = Oj.dump($obj, :mode => :compat)
80
+ $json = Oj.dump($obj)
81
81
  $failed = {} # key is same as String used in tests later
82
82
 
83
83
  def capture_error(tag, orig, load_key, dump_key, &blk)
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.14.4
4
+ version: 2.14.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: 2016-02-04 00:00:00.000000000 Z
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler