oj 3.16.7 → 3.16.9
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/CHANGELOG.md +10 -0
- data/ext/oj/parse.c +16 -14
- data/ext/oj/stream_writer.c +2 -6
- data/ext/oj/usual.c +2 -2
- data/lib/oj/version.rb +1 -1
- data/test/test_parser_usual.rb +4 -0
- data/test/test_writer.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3e57c02a1fe6782596953f34b8e2a2b729a09b5d8e7128dd4633d430ca7aa0c
|
4
|
+
data.tar.gz: 7698f8c0203459d62f4421f11a9c3637b04b5b808ecf87ce4ca057e2fd073762
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 417ada5b645a6ba48e81b52bb72cec97bb4a64595a61252989346a975c1026b3cbc039cbf7cef166b5dbfbdd79554d5c9e5786da3299ce1fd3f2ec70d3ef479f
|
7
|
+
data.tar.gz: ceffb29c6732b107d42091bc8754e8b4174e26e6d8eb9c4162ed8a12a65d37aa2450f9f5398d39242d92fabd46d63be5fc14e0dc003774378e4e6211b02e3f0d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.16.9 - 2024-12-28
|
4
|
+
|
5
|
+
- Fixed `Oj::Parser` create_id size issue #931.
|
6
|
+
|
7
|
+
- Changed parser to be more optimized (PR from @Watson1978)
|
8
|
+
|
9
|
+
## 3.16.8 - 2024-12-14
|
10
|
+
|
11
|
+
- Fixed StreamWriter to write to non-file IO thanks to @jscheid.
|
12
|
+
|
3
13
|
## 3.16.7 - 2024-11-01
|
4
14
|
|
5
15
|
- Changed string_writer_as_json to allow multiple arguments.
|
data/ext/oj/parse.c
CHANGED
@@ -681,7 +681,7 @@ void oj_parse2(ParseInfo pi) {
|
|
681
681
|
pi->cur = pi->json;
|
682
682
|
err_init(&pi->err);
|
683
683
|
while (1) {
|
684
|
-
if (0 < pi->max_depth && pi->max_depth <= pi->stack.tail - pi->stack.head - 1) {
|
684
|
+
if (RB_UNLIKELY(0 < pi->max_depth && pi->max_depth <= pi->stack.tail - pi->stack.head - 1)) {
|
685
685
|
VALUE err_clas = oj_get_json_err_class("NestingError");
|
686
686
|
|
687
687
|
oj_set_error_at(pi, err_clas, __FILE__, __LINE__, "Too deeply nested.");
|
@@ -689,18 +689,20 @@ void oj_parse2(ParseInfo pi) {
|
|
689
689
|
return;
|
690
690
|
}
|
691
691
|
next_non_white(pi);
|
692
|
-
if (
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
}
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
692
|
+
if (first) {
|
693
|
+
// If no tokens are consumed (i.e. empty string), throw a parse error
|
694
|
+
// this is the behavior of JSON.parse in both Ruby and JS.
|
695
|
+
if (RB_UNLIKELY('\0' == *pi->cur && No == pi->options.empty_string)) {
|
696
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character");
|
697
|
+
}
|
698
|
+
} else {
|
699
|
+
if (RB_UNLIKELY('\0' != *pi->cur)) {
|
700
|
+
oj_set_error_at(pi,
|
701
|
+
oj_parse_error_class,
|
702
|
+
__FILE__,
|
703
|
+
__LINE__,
|
704
|
+
"unexpected characters after the JSON document");
|
705
|
+
}
|
704
706
|
}
|
705
707
|
|
706
708
|
switch (*pi->cur++) {
|
@@ -761,7 +763,7 @@ void oj_parse2(ParseInfo pi) {
|
|
761
763
|
case '\0': pi->cur--; return;
|
762
764
|
default: oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character"); return;
|
763
765
|
}
|
764
|
-
if (err_has(&pi->err)) {
|
766
|
+
if (RB_UNLIKELY(err_has(&pi->err))) {
|
765
767
|
return;
|
766
768
|
}
|
767
769
|
if (stack_empty(&pi->stack)) {
|
data/ext/oj/stream_writer.c
CHANGED
@@ -42,7 +42,8 @@ static void stream_writer_write(StreamWriter sw) {
|
|
42
42
|
|
43
43
|
switch (sw->type) {
|
44
44
|
case STRING_IO:
|
45
|
-
case STREAM_IO:
|
45
|
+
case STREAM_IO:
|
46
|
+
case FILE_IO: {
|
46
47
|
volatile VALUE rs = rb_str_new(sw->sw.out.buf, size);
|
47
48
|
|
48
49
|
// Oddly enough, when pushing ASCII characters with UTF-8 encoding or
|
@@ -53,11 +54,6 @@ static void stream_writer_write(StreamWriter sw) {
|
|
53
54
|
rb_funcall(sw->stream, oj_write_id, 1, rs);
|
54
55
|
break;
|
55
56
|
}
|
56
|
-
case FILE_IO:
|
57
|
-
if (size != write(sw->fd, sw->sw.out.buf, size)) {
|
58
|
-
rb_raise(rb_eIOError, "Write failed. [_%d_:%s]\n", errno, strerror(errno));
|
59
|
-
}
|
60
|
-
break;
|
61
57
|
default: rb_raise(rb_eArgError, "expected an IO Object.");
|
62
58
|
}
|
63
59
|
stream_writer_reset_buf(sw);
|
data/ext/oj/usual.c
CHANGED
@@ -834,8 +834,8 @@ static VALUE opt_create_id_set(ojParser p, VALUE value) {
|
|
834
834
|
rb_check_type(value, T_STRING);
|
835
835
|
size_t len = RSTRING_LEN(value);
|
836
836
|
|
837
|
-
if (1 << sizeof(d->create_id_len) <= len) {
|
838
|
-
rb_raise(rb_eArgError, "The create_id values is limited to %d bytes.", 1 << sizeof(d->create_id_len));
|
837
|
+
if (1 << (8 * sizeof(d->create_id_len)) <= len) {
|
838
|
+
rb_raise(rb_eArgError, "The create_id values is limited to %d bytes.", 1 << (8 * sizeof(d->create_id_len)));
|
839
839
|
}
|
840
840
|
d->create_id_len = (uint8_t)len;
|
841
841
|
d->create_id = str_dup(RSTRING_PTR(value), len);
|
data/lib/oj/version.rb
CHANGED
data/test/test_parser_usual.rb
CHANGED
@@ -217,6 +217,10 @@ class UsualTest < Minitest::Test
|
|
217
217
|
|
218
218
|
doc = p.parse('{"a":true,"^":"UsualTest::MyClass","b":false}')
|
219
219
|
assert_equal('UsualTest::MyClass{a: true b: false}', doc.to_s)
|
220
|
+
|
221
|
+
p.create_id = 'class'
|
222
|
+
doc = p.parse('{"a":true,"class":"UsualTest::MyClass","b":false}')
|
223
|
+
assert_equal('UsualTest::MyClass{a: true b: false}', doc.to_s)
|
220
224
|
end
|
221
225
|
|
222
226
|
def test_missing_class
|
data/test/test_writer.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
$LOAD_PATH << __dir__
|
5
5
|
|
6
6
|
require 'helper'
|
7
|
+
require 'open3'
|
7
8
|
|
8
9
|
class OjWriter < Minitest::Test
|
9
10
|
|
@@ -377,4 +378,19 @@ class OjWriter < Minitest::Test
|
|
377
378
|
w.pop()
|
378
379
|
assert_equal(%|{"nothing":null}\n|, output.string())
|
379
380
|
end
|
381
|
+
|
382
|
+
def test_stream_writer_subprocess
|
383
|
+
skip if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
|
384
|
+
|
385
|
+
Open3.popen3("/bin/bash", "-c", "cat > /dev/null") do |stdin, _stdout, _stderr, _wait_thr|
|
386
|
+
w = Oj::StreamWriter.new(stdin, :indent => 0)
|
387
|
+
w.push_array()
|
388
|
+
chunk = "{\"foo\":\"#{"bar"*1000}\"}"
|
389
|
+
1000.times do |_|
|
390
|
+
w.push_json(chunk)
|
391
|
+
end
|
392
|
+
w.pop()
|
393
|
+
stdin.close
|
394
|
+
end
|
395
|
+
end
|
380
396
|
end # OjWriter
|
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.16.
|
4
|
+
version: 3.16.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: 2024-
|
11
|
+
date: 2024-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bigdecimal
|