oj 2.14.4 → 2.14.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/ext/oj/compat.c +2 -0
- data/ext/oj/object.c +2 -0
- data/ext/oj/oj.c +8 -1
- data/ext/oj/parse.c +25 -13
- data/ext/oj/parse.h +1 -0
- data/ext/oj/scp.c +1 -0
- data/ext/oj/sparse.c +3 -0
- data/ext/oj/strict.c +2 -0
- data/lib/oj/version.rb +1 -1
- data/test/perf_compat.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18d01b3bb2476564f6b39dd5df0b8ece9d9dd2a4
|
4
|
+
data.tar.gz: b1927b77d0fad77544118e3d11a137374cf1630d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
162
|
+
**Release 2.14.5**
|
163
163
|
|
164
|
-
-
|
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
|
|
data/ext/oj/compat.c
CHANGED
@@ -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;
|
data/ext/oj/object.c
CHANGED
@@ -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;
|
data/ext/oj/oj.c
CHANGED
@@ -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
|
-
|
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);
|
data/ext/oj/parse.c
CHANGED
@@ -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
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
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;
|
data/ext/oj/parse.h
CHANGED
@@ -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);
|
data/ext/oj/scp.c
CHANGED
data/ext/oj/sparse.c
CHANGED
data/ext/oj/strict.c
CHANGED
@@ -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);
|
data/lib/oj/version.rb
CHANGED
data/test/perf_compat.rb
CHANGED
@@ -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
|
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
|
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
|
+
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-
|
11
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|