oj 3.9.2 → 3.10.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/ext/oj/buf.h +2 -30
- data/ext/oj/cache8.h +1 -29
- data/ext/oj/circarray.c +4 -8
- data/ext/oj/circarray.h +1 -4
- data/ext/oj/code.c +3 -6
- data/ext/oj/code.h +1 -4
- data/ext/oj/compat.c +6 -9
- data/ext/oj/custom.c +8 -7
- data/ext/oj/dump.c +33 -26
- data/ext/oj/dump.h +1 -4
- data/ext/oj/dump_compat.c +9 -14
- data/ext/oj/dump_leaf.c +2 -5
- data/ext/oj/dump_object.c +19 -15
- data/ext/oj/dump_strict.c +7 -9
- data/ext/oj/encode.h +1 -29
- data/ext/oj/err.c +1 -4
- data/ext/oj/err.h +1 -29
- data/ext/oj/extconf.rb +5 -0
- data/ext/oj/fast.c +14 -42
- data/ext/oj/hash.c +4 -32
- data/ext/oj/hash.h +1 -29
- data/ext/oj/hash_test.c +1 -29
- data/ext/oj/mimic_json.c +28 -10
- data/ext/oj/object.c +4 -6
- data/ext/oj/odd.c +1 -4
- data/ext/oj/odd.h +1 -4
- data/ext/oj/oj.c +74 -38
- data/ext/oj/oj.h +9 -7
- data/ext/oj/parse.c +127 -52
- data/ext/oj/parse.h +4 -5
- data/ext/oj/rails.c +38 -8
- data/ext/oj/rails.h +1 -4
- data/ext/oj/reader.c +5 -8
- data/ext/oj/reader.h +2 -5
- data/ext/oj/resolve.c +1 -4
- data/ext/oj/resolve.h +1 -4
- data/ext/oj/rxclass.c +3 -6
- data/ext/oj/rxclass.h +1 -4
- data/ext/oj/saj.c +6 -9
- data/ext/oj/scp.c +1 -4
- data/ext/oj/sparse.c +31 -26
- data/ext/oj/stream_writer.c +4 -9
- data/ext/oj/strict.c +3 -6
- data/ext/oj/string_writer.c +1 -4
- data/ext/oj/trace.c +5 -8
- data/ext/oj/trace.h +1 -4
- data/ext/oj/util.c +1 -1
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +1 -29
- data/ext/oj/val_stack.h +1 -29
- data/ext/oj/wab.c +10 -13
- data/lib/oj/mimic.rb +45 -1
- data/lib/oj/version.rb +1 -1
- data/lib/oj.rb +0 -8
- data/pages/Modes.md +1 -1
- data/pages/Options.md +15 -11
- data/pages/Rails.md +60 -21
- data/test/activesupport5/abstract_unit.rb +45 -0
- data/test/activesupport5/decoding_test.rb +68 -60
- data/test/activesupport5/encoding_test.rb +111 -96
- data/test/activesupport5/encoding_test_cases.rb +33 -25
- data/test/activesupport5/test_helper.rb +43 -21
- data/test/activesupport5/time_zone_test_helpers.rb +18 -3
- data/test/activesupport6/abstract_unit.rb +44 -0
- data/test/activesupport6/decoding_test.rb +133 -0
- data/test/activesupport6/encoding_test.rb +507 -0
- data/test/activesupport6/encoding_test_cases.rb +98 -0
- data/test/activesupport6/test_common.rb +17 -0
- data/test/activesupport6/test_helper.rb +163 -0
- data/test/activesupport6/time_zone_test_helpers.rb +39 -0
- data/test/bar.rb +21 -11
- data/test/baz.rb +16 -0
- data/test/foo.rb +39 -8
- data/test/json_gem/json_common_interface_test.rb +8 -3
- data/test/prec.rb +23 -0
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +14 -8
- data/test/test_custom.rb +36 -6
- data/test/test_integer_range.rb +1 -2
- data/test/test_object.rb +12 -3
- data/test/test_rails.rb +35 -0
- data/test/test_strict.rb +24 -1
- data/test/test_various.rb +42 -64
- data/test/tests.rb +1 -0
- metadata +29 -7
data/ext/oj/rails.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2017, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2017 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include "rails.h"
|
7
4
|
#include "encode.h"
|
@@ -87,7 +84,8 @@ copy_opts(ROptTable src, ROptTable dest) {
|
|
87
84
|
}
|
88
85
|
|
89
86
|
static int
|
90
|
-
dump_attr_cb(ID key, VALUE value,
|
87
|
+
dump_attr_cb(ID key, VALUE value, VALUE ov) {
|
88
|
+
Out out = (Out)ov;
|
91
89
|
int depth = out->depth;
|
92
90
|
size_t size = depth * out->indent + 1;
|
93
91
|
const char *attr = rb_id2name(key);
|
@@ -214,6 +212,8 @@ dump_bigdecimal(VALUE obj, int depth, Out out, bool as_ok) {
|
|
214
212
|
|
215
213
|
if ('I' == *str || 'N' == *str || ('-' == *str && 'I' == str[1])) {
|
216
214
|
oj_dump_nil(Qnil, depth, out, false);
|
215
|
+
} else if (out->opts->int_range_max != 0 || out->opts->int_range_min != 0) {
|
216
|
+
oj_dump_cstr(str, (int)RSTRING_LEN(rstr), 0, 0, out);
|
217
217
|
} else if (Yes == out->opts->bigdec_as_num) {
|
218
218
|
oj_dump_raw(str, (int)RSTRING_LEN(rstr), out);
|
219
219
|
} else {
|
@@ -1012,6 +1012,7 @@ rails_encode(int argc, VALUE *argv, VALUE self) {
|
|
1012
1012
|
static VALUE
|
1013
1013
|
rails_use_standard_json_time_format(VALUE self, VALUE state) {
|
1014
1014
|
if (Qtrue == state || Qfalse == state) {
|
1015
|
+
// no change needed
|
1015
1016
|
} else if (Qnil == state) {
|
1016
1017
|
state = Qfalse;
|
1017
1018
|
} else {
|
@@ -1023,6 +1024,11 @@ rails_use_standard_json_time_format(VALUE self, VALUE state) {
|
|
1023
1024
|
return state;
|
1024
1025
|
}
|
1025
1026
|
|
1027
|
+
static VALUE
|
1028
|
+
rails_use_standard_json_time_format_get(VALUE self) {
|
1029
|
+
return xml_time ? Qtrue : Qfalse;
|
1030
|
+
}
|
1031
|
+
|
1026
1032
|
static VALUE
|
1027
1033
|
rails_escape_html_entities_in_json(VALUE self, VALUE state) {
|
1028
1034
|
rb_iv_set(self, "@escape_html_entities_in_json", state);
|
@@ -1031,10 +1037,16 @@ rails_escape_html_entities_in_json(VALUE self, VALUE state) {
|
|
1031
1037
|
return state;
|
1032
1038
|
}
|
1033
1039
|
|
1040
|
+
static VALUE
|
1041
|
+
rails_escape_html_entities_in_json_get(VALUE self) {
|
1042
|
+
return escape_html ? Qtrue : Qfalse;
|
1043
|
+
}
|
1044
|
+
|
1034
1045
|
static VALUE
|
1035
1046
|
rails_time_precision(VALUE self, VALUE prec) {
|
1036
1047
|
rb_iv_set(self, "@time_precision", prec);
|
1037
1048
|
oj_default_options.sec_prec = NUM2INT(prec);
|
1049
|
+
oj_default_options.sec_prec_set = true;
|
1038
1050
|
|
1039
1051
|
return prec;
|
1040
1052
|
}
|
@@ -1053,7 +1065,12 @@ rails_set_encoder(VALUE self) {
|
|
1053
1065
|
VALUE encoding;
|
1054
1066
|
VALUE pv;
|
1055
1067
|
VALUE verbose;
|
1068
|
+
VALUE enc = resolve_classpath("ActiveSupport::JSON::Encoding");
|
1056
1069
|
|
1070
|
+
if (Qnil != enc) {
|
1071
|
+
escape_html = Qtrue == rb_iv_get(self, "@escape_html_entities_in_json");
|
1072
|
+
xml_time = Qtrue == rb_iv_get(enc, "@use_standard_json_time_format");
|
1073
|
+
}
|
1057
1074
|
if (rb_const_defined_at(rb_cObject, rb_intern("ActiveSupport"))) {
|
1058
1075
|
active = rb_const_get_at(rb_cObject, rb_intern("ActiveSupport"));
|
1059
1076
|
} else {
|
@@ -1070,14 +1087,19 @@ rails_set_encoder(VALUE self) {
|
|
1070
1087
|
rb_gv_set("$VERBOSE", Qfalse);
|
1071
1088
|
rb_undef_method(encoding, "use_standard_json_time_format=");
|
1072
1089
|
rb_define_module_function(encoding, "use_standard_json_time_format=", rails_use_standard_json_time_format, 1);
|
1090
|
+
rb_undef_method(encoding, "use_standard_json_time_format");
|
1091
|
+
rb_define_module_function(encoding, "use_standard_json_time_format", rails_use_standard_json_time_format_get, 0);
|
1073
1092
|
|
1074
1093
|
pv = rb_iv_get(encoding, "@escape_html_entities_in_json");
|
1075
1094
|
escape_html = Qtrue == pv;
|
1076
1095
|
rb_undef_method(encoding, "escape_html_entities_in_json=");
|
1077
1096
|
rb_define_module_function(encoding, "escape_html_entities_in_json=", rails_escape_html_entities_in_json, 1);
|
1097
|
+
rb_undef_method(encoding, "escape_html_entities_in_json");
|
1098
|
+
rb_define_module_function(encoding, "escape_html_entities_in_json", rails_escape_html_entities_in_json_get, 0);
|
1078
1099
|
|
1079
1100
|
pv = rb_iv_get(encoding, "@time_precision");
|
1080
1101
|
oj_default_options.sec_prec = NUM2INT(pv);
|
1102
|
+
oj_default_options.sec_prec_set = true;
|
1081
1103
|
rb_undef_method(encoding, "time_precision=");
|
1082
1104
|
rb_define_module_function(encoding, "time_precision=", rails_time_precision, 1);
|
1083
1105
|
rb_gv_set("$VERBOSE", verbose);
|
@@ -1285,7 +1307,8 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
1285
1307
|
}
|
1286
1308
|
|
1287
1309
|
static int
|
1288
|
-
hash_cb(VALUE key, VALUE value,
|
1310
|
+
hash_cb(VALUE key, VALUE value, VALUE ov) {
|
1311
|
+
Out out = (Out)ov;
|
1289
1312
|
int depth = out->depth;
|
1290
1313
|
long size;
|
1291
1314
|
int rtype = rb_type(key);
|
@@ -1398,14 +1421,17 @@ dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1398
1421
|
|
1399
1422
|
static void
|
1400
1423
|
dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
1424
|
+
VALUE clas;
|
1425
|
+
|
1401
1426
|
if (oj_code_dump(oj_compat_codes, obj, depth, out)) {
|
1402
1427
|
out->argc = 0;
|
1403
1428
|
return;
|
1404
1429
|
}
|
1430
|
+
clas = rb_obj_class(obj);
|
1405
1431
|
if (as_ok) {
|
1406
1432
|
ROpt ro;
|
1407
1433
|
|
1408
|
-
if (NULL != (ro = oj_rails_get_opt(out->ropts,
|
1434
|
+
if (NULL != (ro = oj_rails_get_opt(out->ropts, clas)) && ro->on) {
|
1409
1435
|
ro->dump(obj, depth, out, as_ok);
|
1410
1436
|
} else if (Yes == out->opts->raw_json && rb_respond_to(obj, oj_raw_json_id)) {
|
1411
1437
|
oj_dump_raw_json(obj, depth, out);
|
@@ -1413,6 +1439,8 @@ dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1413
1439
|
dump_as_json(obj, depth, out, true);
|
1414
1440
|
} else if (rb_respond_to(obj, oj_to_hash_id)) {
|
1415
1441
|
dump_to_hash(obj, depth, out);
|
1442
|
+
} else if (oj_bigdecimal_class == clas) {
|
1443
|
+
dump_bigdecimal(obj, depth, out, false);
|
1416
1444
|
} else {
|
1417
1445
|
oj_dump_obj_to_s(obj, out);
|
1418
1446
|
}
|
@@ -1421,6 +1449,8 @@ dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1421
1449
|
} else if (rb_respond_to(obj, oj_to_hash_id)) {
|
1422
1450
|
// Always attempt to_hash.
|
1423
1451
|
dump_to_hash(obj, depth, out);
|
1452
|
+
} else if (oj_bigdecimal_class == clas) {
|
1453
|
+
dump_bigdecimal(obj, depth, out, false);
|
1424
1454
|
} else {
|
1425
1455
|
oj_dump_obj_to_s(obj, out);
|
1426
1456
|
}
|
@@ -1439,7 +1469,7 @@ static DumpFunc rails_funcs[] = {
|
|
1439
1469
|
dump_hash, // RUBY_T_HASH = 0x08,
|
1440
1470
|
dump_obj, // RUBY_T_STRUCT = 0x09,
|
1441
1471
|
oj_dump_bignum, // RUBY_T_BIGNUM = 0x0a,
|
1442
|
-
|
1472
|
+
dump_as_string, // RUBY_T_FILE = 0x0b,
|
1443
1473
|
dump_obj, // RUBY_T_DATA = 0x0c,
|
1444
1474
|
NULL, // RUBY_T_MATCH = 0x0d,
|
1445
1475
|
// Rails raises a stack error on Complex and Rational. It also corrupts
|
data/ext/oj/rails.h
CHANGED
data/ext/oj/reader.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2011, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include <stdlib.h>
|
7
4
|
#include <errno.h>
|
@@ -9,7 +6,7 @@
|
|
9
6
|
#include <strings.h>
|
10
7
|
#include <sys/types.h>
|
11
8
|
#if NEEDS_UIO
|
12
|
-
#include <sys/uio.h>
|
9
|
+
#include <sys/uio.h>
|
13
10
|
#endif
|
14
11
|
#include <unistd.h>
|
15
12
|
#include <time.h>
|
@@ -78,13 +75,13 @@ oj_reader_init(Reader reader, VALUE io, int fd, bool to_s) {
|
|
78
75
|
reader->io = io;
|
79
76
|
} else if (to_s) {
|
80
77
|
volatile VALUE rstr = rb_funcall(io, oj_to_s_id, 0);
|
81
|
-
|
78
|
+
|
82
79
|
reader->read_func = 0;
|
83
80
|
reader->in_str = StringValuePtr(rstr);
|
84
81
|
reader->head = (char*)reader->in_str;
|
85
82
|
reader->tail = reader->head;
|
86
83
|
reader->read_end = reader->head + RSTRING_LEN(rstr);
|
87
|
-
} else {
|
84
|
+
} else {
|
88
85
|
rb_raise(rb_eArgError, "parser io argument must be a String or respond to readpartial() or read().\n");
|
89
86
|
}
|
90
87
|
}
|
@@ -107,7 +104,7 @@ oj_reader_read(Reader reader) {
|
|
107
104
|
if (0 >= shift) { /* no space left so allocate more */
|
108
105
|
const char *old = reader->head;
|
109
106
|
size_t size = reader->end - reader->head + BUF_PAD;
|
110
|
-
|
107
|
+
|
111
108
|
if (reader->head == reader->base) {
|
112
109
|
reader->head = ALLOC_N(char, size * 2);
|
113
110
|
memcpy((char*)reader->head, old, size);
|
data/ext/oj/reader.h
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2011, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#ifndef OJ_READER_H
|
7
4
|
#define OJ_READER_H
|
@@ -43,7 +40,7 @@ reader_get(Reader reader) {
|
|
43
40
|
}
|
44
41
|
reader->col++;
|
45
42
|
reader->pos++;
|
46
|
-
|
43
|
+
|
47
44
|
return *reader->tail++;
|
48
45
|
}
|
49
46
|
|
data/ext/oj/resolve.c
CHANGED
data/ext/oj/resolve.h
CHANGED
data/ext/oj/rxclass.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2017, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2017 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include <sys/types.h>
|
7
4
|
#include <stdlib.h>
|
@@ -101,12 +98,12 @@ VALUE
|
|
101
98
|
oj_rxclass_match(RxClass rc, const char *str, int len) {
|
102
99
|
RxC rxc;
|
103
100
|
char buf[4096];
|
104
|
-
|
101
|
+
|
105
102
|
for (rxc = rc->head; NULL != rxc; rxc = rxc->next) {
|
106
103
|
if (Qnil != rxc->rrx) {
|
107
104
|
// Must use a valiabel for this to work.
|
108
105
|
volatile VALUE rstr = rb_str_new(str, len);
|
109
|
-
|
106
|
+
|
110
107
|
//if (Qtrue == rb_funcall(rxc->rrx, rb_intern("match?"), 1, rstr)) {
|
111
108
|
if (Qnil != rb_funcall(rxc->rrx, rb_intern("match"), 1, rstr)) {
|
112
109
|
return rxc->clas;
|
data/ext/oj/rxclass.h
CHANGED
data/ext/oj/saj.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2012, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2012 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#if !IS_WINDOWS
|
7
4
|
#include <sys/resource.h> /* for getrlimit() on linux */
|
@@ -213,7 +210,7 @@ read_next(ParseInfo pi, const char *key) {
|
|
213
210
|
static void
|
214
211
|
read_hash(ParseInfo pi, const char *key) {
|
215
212
|
const char *ks;
|
216
|
-
|
213
|
+
|
217
214
|
if (pi->has_hash_start) {
|
218
215
|
call_no_value(pi->handler, oj_hash_start_id, key);
|
219
216
|
}
|
@@ -378,7 +375,7 @@ read_num(ParseInfo pi, const char *key) {
|
|
378
375
|
if (0 == e && 0 == a && 1 == div) {
|
379
376
|
if (big) {
|
380
377
|
char c = *pi->s;
|
381
|
-
|
378
|
+
|
382
379
|
*pi->s = '\0';
|
383
380
|
if (pi->has_add_value) {
|
384
381
|
call_add_value(pi->handler, rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(start)), key);
|
@@ -396,7 +393,7 @@ read_num(ParseInfo pi, const char *key) {
|
|
396
393
|
} else { /* decimal */
|
397
394
|
if (big) {
|
398
395
|
char c = *pi->s;
|
399
|
-
|
396
|
+
|
400
397
|
*pi->s = '\0';
|
401
398
|
if (pi->has_add_value) {
|
402
399
|
call_add_value(pi->handler, rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(start)), key);
|
@@ -541,7 +538,7 @@ read_quoted_value(ParseInfo pi) {
|
|
541
538
|
char *h = pi->s; /* head */
|
542
539
|
char *t = h; /* tail */
|
543
540
|
uint32_t code;
|
544
|
-
|
541
|
+
|
545
542
|
h++; /* skip quote character */
|
546
543
|
t++;
|
547
544
|
value = h;
|
@@ -679,7 +676,7 @@ oj_saj_parse(int argc, VALUE *argv, VALUE self) {
|
|
679
676
|
} else {
|
680
677
|
VALUE clas = rb_obj_class(input);
|
681
678
|
volatile VALUE s;
|
682
|
-
|
679
|
+
|
683
680
|
if (oj_stringio_class == clas) {
|
684
681
|
s = rb_funcall2(input, oj_string_id, 0, 0);
|
685
682
|
len = RSTRING_LEN(s) + 1;
|
data/ext/oj/scp.c
CHANGED
data/ext/oj/sparse.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2013, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2013 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include <stdlib.h>
|
7
4
|
#include <stdio.h>
|
@@ -228,17 +225,6 @@ read_escaped_str(ParseInfo pi) {
|
|
228
225
|
case '"': buf_append(&buf, '"'); break;
|
229
226
|
case '/': buf_append(&buf, '/'); break;
|
230
227
|
case '\\': buf_append(&buf, '\\'); break;
|
231
|
-
case '\'':
|
232
|
-
// The json gem claims this is not an error despite the
|
233
|
-
// ECMA-404 indicating it is not valid.
|
234
|
-
if (CompatMode == pi->options.mode) {
|
235
|
-
buf_append(&buf, '\'');
|
236
|
-
} else {
|
237
|
-
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid escaped character");
|
238
|
-
buf_cleanup(&buf);
|
239
|
-
return;
|
240
|
-
}
|
241
|
-
break;
|
242
228
|
case 'u':
|
243
229
|
if (0 == (code = read_hex(pi)) && err_has(&pi->err)) {
|
244
230
|
buf_cleanup(&buf);
|
@@ -276,6 +262,12 @@ read_escaped_str(ParseInfo pi) {
|
|
276
262
|
}
|
277
263
|
break;
|
278
264
|
default:
|
265
|
+
// The json gem claims this is not an error despite the
|
266
|
+
// ECMA-404 indicating it is not valid.
|
267
|
+
if (CompatMode == pi->options.mode) {
|
268
|
+
buf_append(&buf, c);
|
269
|
+
break;
|
270
|
+
}
|
279
271
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid escaped character");
|
280
272
|
buf_cleanup(&buf);
|
281
273
|
return;
|
@@ -407,8 +399,10 @@ read_num(ParseInfo pi) {
|
|
407
399
|
ni.infinity = 0;
|
408
400
|
ni.nan = 0;
|
409
401
|
ni.neg = 0;
|
410
|
-
ni.
|
411
|
-
ni.no_big = (FloatDec == pi->options.bigdec_load);
|
402
|
+
ni.has_exp = 0;
|
403
|
+
ni.no_big = (FloatDec == pi->options.bigdec_load || FastDec == pi->options.bigdec_load || RubyDec == pi->options.bigdec_load);
|
404
|
+
ni.bigdec_load = pi->options.bigdec_load;
|
405
|
+
|
412
406
|
c = reader_get(&pi->rd);
|
413
407
|
if ('-' == c) {
|
414
408
|
c = reader_get(&pi->rd);
|
@@ -469,18 +463,26 @@ read_num(ParseInfo pi) {
|
|
469
463
|
if (0 < ni.num || 0 < ni.i) {
|
470
464
|
dec_cnt++;
|
471
465
|
}
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
466
|
+
if (INT64_MAX <= ni.div) {
|
467
|
+
if (!ni.no_big) {
|
468
|
+
ni.big = true;
|
469
|
+
}
|
470
|
+
} else {
|
471
|
+
ni.num = ni.num * 10 + d;
|
472
|
+
ni.div *= 10;
|
473
|
+
ni.di++;
|
474
|
+
if (INT64_MAX <= ni.div || DEC_MAX < dec_cnt) {
|
475
|
+
if (!ni.no_big) {
|
476
|
+
ni.big = true;
|
477
|
+
}
|
478
|
+
}
|
477
479
|
}
|
478
480
|
}
|
479
481
|
}
|
480
482
|
if ('e' == c || 'E' == c) {
|
481
483
|
int eneg = 0;
|
482
484
|
|
483
|
-
ni.
|
485
|
+
ni.has_exp = 1;
|
484
486
|
c = reader_get(&pi->rd);
|
485
487
|
if ('-' == c) {
|
486
488
|
c = reader_get(&pi->rd);
|
@@ -539,7 +541,8 @@ read_nan(ParseInfo pi) {
|
|
539
541
|
ni.infinity = 0;
|
540
542
|
ni.nan = 1;
|
541
543
|
ni.neg = 0;
|
542
|
-
ni.no_big = (FloatDec == pi->options.bigdec_load);
|
544
|
+
ni.no_big = (FloatDec == pi->options.bigdec_load || FastDec == pi->options.bigdec_load || RubyDec == pi->options.bigdec_load);
|
545
|
+
ni.bigdec_load = pi->options.bigdec_load;
|
543
546
|
|
544
547
|
if ('a' != reader_get(&pi->rd) ||
|
545
548
|
('N' != (c = reader_get(&pi->rd)) && 'n' != c)) {
|
@@ -736,7 +739,8 @@ oj_sparse2(ParseInfo pi) {
|
|
736
739
|
ni.infinity = 0;
|
737
740
|
ni.nan = 1;
|
738
741
|
ni.neg = 0;
|
739
|
-
ni.no_big = (FloatDec == pi->options.bigdec_load);
|
742
|
+
ni.no_big = (FloatDec == pi->options.bigdec_load || RubyDec == pi->options.bigdec_load || FastDec == pi->options.bigdec_load);
|
743
|
+
ni.bigdec_load = pi->options.bigdec_load;
|
740
744
|
add_num_value(pi, &ni);
|
741
745
|
} else {
|
742
746
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid token");
|
@@ -773,6 +777,7 @@ oj_sparse2(ParseInfo pi) {
|
|
773
777
|
first = 0;
|
774
778
|
}
|
775
779
|
start = pi->rd.pos;
|
780
|
+
// TBD break if option set to allow that
|
776
781
|
}
|
777
782
|
}
|
778
783
|
}
|
@@ -899,7 +904,7 @@ CLEANUP:
|
|
899
904
|
VALUE args[] = { oj_encode(rb_str_new2(pi->err.msg)) };
|
900
905
|
|
901
906
|
if (pi->err.clas == oj_parse_error_class) {
|
902
|
-
// The error was an Oj::ParseError so change to a JSON::
|
907
|
+
// The error was an Oj::ParseError so change to a JSON::ParserError.
|
903
908
|
pi->err.clas = oj_json_parser_error_class;
|
904
909
|
}
|
905
910
|
rb_exc_raise(rb_class_new_instance(1, args, pi->err.clas));
|
data/ext/oj/stream_writer.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2012, 2017, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2012, 2017 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include <errno.h>
|
7
4
|
|
@@ -86,7 +83,7 @@ stream_writer_new(int argc, VALUE *argv, VALUE self) {
|
|
86
83
|
#if !IS_WINDOWS
|
87
84
|
VALUE s;
|
88
85
|
#endif
|
89
|
-
|
86
|
+
|
90
87
|
if (oj_stringio_class == clas) {
|
91
88
|
type = STRING_IO;
|
92
89
|
#if !IS_WINDOWS
|
@@ -107,7 +104,7 @@ stream_writer_new(int argc, VALUE *argv, VALUE self) {
|
|
107
104
|
|
108
105
|
if (Qundef == buffer_size_sym) {
|
109
106
|
buffer_size_sym = ID2SYM(rb_intern("buffer_size")); rb_gc_register_address(&buffer_size_sym);
|
110
|
-
|
107
|
+
|
111
108
|
}
|
112
109
|
if (Qnil != (v = rb_hash_lookup(argv[1], buffer_size_sym))) {
|
113
110
|
#ifdef RUBY_INTEGER_UNIFICATION
|
@@ -340,7 +337,7 @@ stream_writer_flush(VALUE self) {
|
|
340
337
|
}
|
341
338
|
|
342
339
|
/* Document-class: Oj::StreamWriter
|
343
|
-
*
|
340
|
+
*
|
344
341
|
* Supports building a JSON document one element at a time. Build the IO stream
|
345
342
|
* document by pushing values into the document. Pushing an array or an object
|
346
343
|
* will create that element in the JSON document and subsequent pushes will add
|
@@ -359,5 +356,3 @@ oj_stream_writer_init() {
|
|
359
356
|
rb_define_method(oj_stream_writer_class, "pop_all", stream_writer_pop_all, 0);
|
360
357
|
rb_define_method(oj_stream_writer_class, "flush", stream_writer_flush, 0);
|
361
358
|
}
|
362
|
-
|
363
|
-
|
data/ext/oj/strict.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2012, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2012 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include <stdlib.h>
|
7
4
|
#include <stdio.h>
|
@@ -102,7 +99,7 @@ hash_set_cstr(ParseInfo pi, Val parent, const char *str, size_t len, const char
|
|
102
99
|
static void
|
103
100
|
hash_set_num(ParseInfo pi, Val parent, NumInfo ni) {
|
104
101
|
volatile VALUE v;
|
105
|
-
|
102
|
+
|
106
103
|
if (ni->infinity || ni->nan) {
|
107
104
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
|
108
105
|
}
|
@@ -143,7 +140,7 @@ array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
143
140
|
static void
|
144
141
|
array_append_num(ParseInfo pi, NumInfo ni) {
|
145
142
|
volatile VALUE v;
|
146
|
-
|
143
|
+
|
147
144
|
if (ni->infinity || ni->nan) {
|
148
145
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
|
149
146
|
}
|
data/ext/oj/string_writer.c
CHANGED
data/ext/oj/trace.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2018, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2018 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include "parse.h"
|
7
4
|
#include "trace.h"
|
@@ -37,7 +34,7 @@ oj_trace_parse_call(const char *func, ParseInfo pi, const char *file, int line,
|
|
37
34
|
char fmt[64];
|
38
35
|
char indent[MAX_INDENT];
|
39
36
|
int depth = (int)(stack_size(&pi->stack) * 2);
|
40
|
-
|
37
|
+
|
41
38
|
fill_indent(indent, depth);
|
42
39
|
sprintf(fmt, "#0:%%13s:%%3d:Oj:-:%%%ds %%s %%s\n", depth);
|
43
40
|
printf(fmt, file, line, indent, func, rb_obj_classname(obj));
|
@@ -48,7 +45,7 @@ oj_trace_parse_in(const char *func, ParseInfo pi, const char *file, int line) {
|
|
48
45
|
char fmt[64];
|
49
46
|
char indent[MAX_INDENT];
|
50
47
|
int depth = (int)(stack_size(&pi->stack) * 2);
|
51
|
-
|
48
|
+
|
52
49
|
fill_indent(indent, depth);
|
53
50
|
sprintf(fmt, "#0:%%13s:%%3d:Oj:}:%%%ds %%s\n", depth);
|
54
51
|
printf(fmt, file, line, indent, func);
|
@@ -61,7 +58,7 @@ oj_trace_parse_hash_end(ParseInfo pi, const char *file, int line) {
|
|
61
58
|
int depth = (int)(stack_size(&pi->stack) * 2 - 2);
|
62
59
|
Val v = stack_peek(&pi->stack);
|
63
60
|
VALUE obj = v->val;
|
64
|
-
|
61
|
+
|
65
62
|
fill_indent(indent, depth);
|
66
63
|
sprintf(fmt, "#0:%%13s:%%3d:Oj:{:%%%ds hash_end %%s\n", depth);
|
67
64
|
printf(fmt, file, line, indent, rb_obj_classname(obj));
|
@@ -72,7 +69,7 @@ oj_trace_parse_array_end(ParseInfo pi, const char *file, int line) {
|
|
72
69
|
char fmt[64];
|
73
70
|
char indent[MAX_INDENT];
|
74
71
|
int depth = (int)(stack_size(&pi->stack) * 2);
|
75
|
-
|
72
|
+
|
76
73
|
fill_indent(indent, depth);
|
77
74
|
sprintf(fmt, "#0:%%13s:%%3d:Oj:{:%%%ds array_ned\n", depth);
|
78
75
|
printf(fmt, file, line, indent);
|
data/ext/oj/trace.h
CHANGED
data/ext/oj/util.c
CHANGED
data/ext/oj/util.h
CHANGED
data/ext/oj/val_stack.c
CHANGED
@@ -1,32 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2011, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
8
|
-
* - Redistributions of source code must retain the above copyright notice, this
|
9
|
-
* list of conditions and the following disclaimer.
|
10
|
-
*
|
11
|
-
* - Redistributions in binary form must reproduce the above copyright notice,
|
12
|
-
* this list of conditions and the following disclaimer in the documentation
|
13
|
-
* and/or other materials provided with the distribution.
|
14
|
-
*
|
15
|
-
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
16
|
-
* used to endorse or promote products derived from this software without
|
17
|
-
* specific prior written permission.
|
18
|
-
*
|
19
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
30
2
|
|
31
3
|
#include <string.h>
|
32
4
|
|
data/ext/oj/val_stack.h
CHANGED
@@ -1,32 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2011, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
8
|
-
* - Redistributions of source code must retain the above copyright notice, this
|
9
|
-
* list of conditions and the following disclaimer.
|
10
|
-
*
|
11
|
-
* - Redistributions in binary form must reproduce the above copyright notice,
|
12
|
-
* this list of conditions and the following disclaimer in the documentation
|
13
|
-
* and/or other materials provided with the distribution.
|
14
|
-
*
|
15
|
-
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
16
|
-
* used to endorse or promote products derived from this software without
|
17
|
-
* specific prior written permission.
|
18
|
-
*
|
19
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
30
2
|
|
31
3
|
#ifndef OJ_VAL_STACK_H
|
32
4
|
#define OJ_VAL_STACK_H
|