oj 3.0.8 → 3.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/oj/dump.c +1 -1
- data/ext/oj/dump_compat.c +1 -1
- data/ext/oj/mimic_json.c +6 -1
- data/ext/oj/rails.c +1 -1
- data/ext/oj/reader.c +10 -2
- data/ext/oj/reader.h +1 -1
- data/ext/oj/sparse.c +1 -1
- data/lib/oj/version.rb +1 -1
- data/pages/Modes.md +4 -4
- data/test/test_compat.rb +21 -18
- 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: 12393f7e80f652ce9474b8ef98704a943a3dbb7e
|
4
|
+
data.tar.gz: 97f4f982b38b117b27736018df3050ea40da2388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 981d90bd2dd8bf6e6f1d5893d0bb25ba1429fe4399c9ea1b3574a6b2d137dc0be411c4a645fc387381e305e6e5b4daad9ae4e73b4aa896090ab79ceb790b9fd9
|
7
|
+
data.tar.gz: 4db2afa9967ce0a6ff2bd35392b377f156d06d5f4faea907ec750265f6f9ddb3336c8caf47165cfb3954290cea6629c890d58c5276149fb946b359f79987ceca
|
data/ext/oj/dump.c
CHANGED
@@ -775,8 +775,8 @@ oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out) {
|
|
775
775
|
if (0x80 == (uint8_t)str[1] && (0xa8 == (uint8_t)str[2] || 0xa9 == (uint8_t)str[2])) {
|
776
776
|
str = dump_unicode(str, end, out);
|
777
777
|
} else {
|
778
|
+
check_start = check_unicode(str, end);
|
778
779
|
*out->cur++ = *str;
|
779
|
-
check_start = str + 3;
|
780
780
|
}
|
781
781
|
break;
|
782
782
|
}
|
data/ext/oj/dump_compat.c
CHANGED
@@ -619,7 +619,7 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
619
619
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
620
620
|
|
621
621
|
strcpy(buf, rb_string_value_ptr((VALUE*)&rstr));
|
622
|
-
cnt = RSTRING_LEN(rstr);
|
622
|
+
cnt = (int)RSTRING_LEN(rstr);
|
623
623
|
}
|
624
624
|
assure_size(out, cnt);
|
625
625
|
for (b = buf; '\0' != *b; b++) {
|
data/ext/oj/mimic_json.c
CHANGED
@@ -489,6 +489,7 @@ mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
|
|
489
489
|
pi.options.create_ok = No;
|
490
490
|
pi.options.allow_nan = (bang ? Yes : No);
|
491
491
|
pi.options.nilnil = No;
|
492
|
+
pi.options.mode = CompatMode;
|
492
493
|
pi.max_depth = 100;
|
493
494
|
|
494
495
|
if (2 <= argc) {
|
@@ -550,7 +551,11 @@ mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
|
|
550
551
|
}
|
551
552
|
*args = *argv;
|
552
553
|
|
553
|
-
|
554
|
+
if (T_STRING == rb_type(*args)) {
|
555
|
+
return oj_pi_parse(1, args, &pi, 0, 0, false);
|
556
|
+
} else {
|
557
|
+
return oj_pi_sparse(1, args, &pi, 0);
|
558
|
+
}
|
554
559
|
}
|
555
560
|
|
556
561
|
/* Document-method: parse
|
data/ext/oj/rails.c
CHANGED
@@ -943,7 +943,7 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
943
943
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
944
944
|
|
945
945
|
strcpy(buf, rb_string_value_ptr((VALUE*)&rstr));
|
946
|
-
cnt = RSTRING_LEN(rstr);
|
946
|
+
cnt = (int)RSTRING_LEN(rstr);
|
947
947
|
}
|
948
948
|
}
|
949
949
|
assure_size(out, cnt);
|
data/ext/oj/reader.c
CHANGED
@@ -29,7 +29,7 @@ static int read_from_io_partial(Reader reader);
|
|
29
29
|
//static int read_from_str(Reader reader);
|
30
30
|
|
31
31
|
void
|
32
|
-
oj_reader_init(Reader reader, VALUE io, int fd) {
|
32
|
+
oj_reader_init(Reader reader, VALUE io, int fd, bool to_s) {
|
33
33
|
VALUE io_class = rb_obj_class(io);
|
34
34
|
VALUE stat;
|
35
35
|
VALUE ftype;
|
@@ -76,7 +76,15 @@ oj_reader_init(Reader reader, VALUE io, int fd) {
|
|
76
76
|
} else if (rb_respond_to(io, oj_read_id)) {
|
77
77
|
reader->read_func = read_from_io;
|
78
78
|
reader->io = io;
|
79
|
-
} else {
|
79
|
+
} else if (to_s) {
|
80
|
+
volatile VALUE rstr = rb_funcall(io, oj_to_s_id, 0);
|
81
|
+
|
82
|
+
reader->read_func = 0;
|
83
|
+
reader->in_str = StringValuePtr(rstr);
|
84
|
+
reader->head = (char*)reader->in_str;
|
85
|
+
reader->tail = reader->head;
|
86
|
+
reader->read_end = reader->head + RSTRING_LEN(rstr);
|
87
|
+
} else {
|
80
88
|
rb_raise(rb_eArgError, "parser io argument must be a String or respond to readpartial() or read().\n");
|
81
89
|
}
|
82
90
|
}
|
data/ext/oj/reader.h
CHANGED
data/ext/oj/sparse.c
CHANGED
@@ -832,7 +832,7 @@ oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd) {
|
|
832
832
|
} else {
|
833
833
|
pi->proc = Qundef;
|
834
834
|
}
|
835
|
-
oj_reader_init(&pi->rd, input, fd);
|
835
|
+
oj_reader_init(&pi->rd, input, fd, CompatMode == pi->options.mode);
|
836
836
|
pi->json = 0; // indicates reader is in use
|
837
837
|
|
838
838
|
if (Yes == pi->options.circular) {
|
data/lib/oj/version.rb
CHANGED
data/pages/Modes.md
CHANGED
@@ -39,7 +39,7 @@ if a non-native type is encountered instead of raising an Exception.
|
|
39
39
|
The `:compat` mode mimics the json gem. The json gem is built around the use
|
40
40
|
of the `to_json(*)` method defined for a class. Oj attempts to provide the
|
41
41
|
same functionality by being a drop in replacement with a few
|
42
|
-
exceptions. [{file:JsonGem.md}](
|
42
|
+
exceptions. [{file:JsonGem.md}](JsonGem.md) includes more details on
|
43
43
|
compatibility and use.
|
44
44
|
|
45
45
|
## :rails Mode
|
@@ -47,7 +47,7 @@ compatibility and use.
|
|
47
47
|
The `:rails` mode mimics the ActiveSupport version 5 encoder. Rails and
|
48
48
|
ActiveSupport are built around the use of the `as_json(*)` method defined for
|
49
49
|
a class. Oj attempts to provide the same functionality by being a drop in
|
50
|
-
replacement with a few exceptions. [{file:Rails.md}](
|
50
|
+
replacement with a few exceptions. [{file:Rails.md}](Rails.md) includes
|
51
51
|
more details on compatibility and use.
|
52
52
|
|
53
53
|
## :object Mode
|
@@ -58,7 +58,7 @@ default mode unless changed in the Oj default options. In :object mode Oj
|
|
58
58
|
generates JSON that follows conventions which allow Class and other
|
59
59
|
information such as Object IDs for circular reference detection to be encoded
|
60
60
|
in a JSON document. The formatting follows the rules describe on the
|
61
|
-
[{file:Encoding.md}](
|
61
|
+
[{file:Encoding.md}](Encoding.md) page.
|
62
62
|
|
63
63
|
## :custom Mode
|
64
64
|
|
@@ -68,7 +68,7 @@ some special aspect that makes it unique. For example, the `:object` mode has
|
|
68
68
|
it's own unique format for object dumping and loading. The `:compat` mode
|
69
69
|
mimic the json gem including methods called for encoding and inconsistencies
|
70
70
|
between `JSON.dump()`, `JSON.generate()`, and `JSON()`. More details on the
|
71
|
-
[{file:Custom.md}](
|
71
|
+
[{file:Custom.md}](Custom.md) page.
|
72
72
|
|
73
73
|
## Options Matrix
|
74
74
|
|
data/test/test_compat.rb
CHANGED
@@ -47,6 +47,15 @@ class CompatJuice < Minitest::Test
|
|
47
47
|
end
|
48
48
|
end # Argy
|
49
49
|
|
50
|
+
class Stringy
|
51
|
+
def initialize()
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_s()
|
55
|
+
%|[1,2]|
|
56
|
+
end
|
57
|
+
end # Stringy
|
58
|
+
|
50
59
|
module One
|
51
60
|
module Two
|
52
61
|
module Three
|
@@ -275,12 +284,7 @@ class CompatJuice < Minitest::Test
|
|
275
284
|
end
|
276
285
|
|
277
286
|
def test_infinity
|
278
|
-
|
279
|
-
Oj.load('Infinity', :mode => :strict)
|
280
|
-
fail()
|
281
|
-
rescue Oj::ParseError
|
282
|
-
assert(true)
|
283
|
-
end
|
287
|
+
assert_raises(Oj::ParseError) { Oj.load('Infinity', :mode => :strict) }
|
284
288
|
x = Oj.load('Infinity', :mode => :compat)
|
285
289
|
assert_equal('Infinity', x.to_s)
|
286
290
|
end
|
@@ -461,21 +465,20 @@ class CompatJuice < Minitest::Test
|
|
461
465
|
end
|
462
466
|
|
463
467
|
def test_bad_unicode
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
end
|
468
|
+
assert_raises() { Oj.to_json("\xE4xy") }
|
469
|
+
end
|
470
|
+
|
471
|
+
def test_bad_unicode_e2
|
472
|
+
assert_raises() { Oj.to_json("L\xE2m ") }
|
470
473
|
end
|
471
474
|
|
472
475
|
def test_bad_unicode_start
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
476
|
+
assert_raises() { Oj.to_json("\x8abc") }
|
477
|
+
end
|
478
|
+
|
479
|
+
def test_parse_to_s
|
480
|
+
s = Stringy.new
|
481
|
+
assert_equal([1,2], Oj.load(s, :mode => :compat))
|
479
482
|
end
|
480
483
|
|
481
484
|
def dump_and_load(obj, trace=false)
|
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: 3.0.
|
4
|
+
version: 3.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|