oj 3.16.6 → 3.16.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/ext/oj/mimic_json.c +5 -1
- data/ext/oj/rails.c +2 -0
- data/ext/oj/stream_writer.c +2 -6
- data/ext/oj/string_writer.c +4 -4
- data/lib/oj/version.rb +1 -1
- data/test/test_compat.rb +1 -1
- 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: dd892ffebade1cd09db195de3776e8243b6cff9da4cb75ab57bc80c7b41d7adc
|
4
|
+
data.tar.gz: ba7345e84005d76de67001c6d42dd7be457b8ca62c35fd3f03ea90779d818d3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bd02aae21bc2ccb6855a86ee68f3810caa76df4db695fb1d400e7c200813e4ed8f8244c88545ca16f8bf8c39063d5f38ac6f76afafdf655939868a683b66cb3
|
7
|
+
data.tar.gz: 939ffdbf9336eda7e261c8acbab50a55b868be7c3574daaa9520deae51e5bcf615759265cd0ad54886f7faf49634c31db7ae7523e18edb3c0632f43fc199841f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.16.8 - 2024-12-14
|
4
|
+
|
5
|
+
- Fixed StreamWriter to write to non-file IO thanks to @jscheid.
|
6
|
+
|
7
|
+
## 3.16.7 - 2024-11-01
|
8
|
+
|
9
|
+
- Changed string_writer_as_json to allow multiple arguments.
|
10
|
+
|
11
|
+
- Fixed Global variable registration added to mimic_json and rails code thanks to @byroot.
|
12
|
+
|
3
13
|
## 3.16.6 - 2024-09-09
|
4
14
|
|
5
15
|
- Fixed issue with Rails 7.2 that changed the order of calls to to_json and as_json.
|
data/ext/oj/mimic_json.c
CHANGED
@@ -837,11 +837,15 @@ void oj_mimic_json_methods(VALUE json) {
|
|
837
837
|
} else {
|
838
838
|
json_error = rb_define_class_under(json, "JSONError", rb_eStandardError);
|
839
839
|
}
|
840
|
+
|
841
|
+
rb_global_variable(&oj_json_parser_error_class);
|
840
842
|
if (rb_const_defined_at(json, rb_intern("ParserError"))) {
|
841
843
|
oj_json_parser_error_class = rb_const_get(json, rb_intern("ParserError"));
|
842
844
|
} else {
|
843
845
|
oj_json_parser_error_class = rb_define_class_under(json, "ParserError", json_error);
|
844
846
|
}
|
847
|
+
|
848
|
+
rb_global_variable(&oj_json_generator_error_class);
|
845
849
|
if (rb_const_defined_at(json, rb_intern("GeneratorError"))) {
|
846
850
|
oj_json_generator_error_class = rb_const_get(json, rb_intern("GeneratorError"));
|
847
851
|
} else {
|
@@ -867,8 +871,8 @@ void oj_mimic_json_methods(VALUE json) {
|
|
867
871
|
rb_require("oj/state");
|
868
872
|
}
|
869
873
|
// Pull in the JSON::State mimic file.
|
874
|
+
rb_global_variable(&state_class);
|
870
875
|
state_class = rb_const_get_at(generator, rb_intern("State"));
|
871
|
-
rb_gc_register_mark_object(state_class);
|
872
876
|
}
|
873
877
|
|
874
878
|
/* Document-module: JSON
|
data/ext/oj/rails.c
CHANGED
@@ -1101,6 +1101,8 @@ static VALUE rails_set_decoder(VALUE self) {
|
|
1101
1101
|
} else {
|
1102
1102
|
json_error = rb_define_class_under(json, "JSONError", rb_eStandardError);
|
1103
1103
|
}
|
1104
|
+
|
1105
|
+
rb_global_variable(&oj_json_parser_error_class);
|
1104
1106
|
if (rb_const_defined_at(json, rb_intern("ParserError"))) {
|
1105
1107
|
oj_json_parser_error_class = rb_const_get(json, rb_intern("ParserError"));
|
1106
1108
|
} else {
|
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/string_writer.c
CHANGED
@@ -475,16 +475,16 @@ static VALUE str_writer_to_s(VALUE self) {
|
|
475
475
|
}
|
476
476
|
|
477
477
|
/* Document-method: as_json
|
478
|
-
* call-seq: as_json()
|
478
|
+
* call-seq: as_json(*)
|
479
479
|
*
|
480
480
|
* Returns the contents of the writer as a JSON element. If called from inside
|
481
481
|
* an array or hash by Oj the raw buffer will be used othersize a more
|
482
482
|
* inefficient parse of the contents and a return of the result is
|
483
|
-
* completed. The parse uses the strict mode.
|
483
|
+
* completed. The parse uses the strict mode. Optional arguments are ignored.
|
484
484
|
*
|
485
485
|
* *return* [_Hash_|_Array_|_String_|_Integer_|_Float_|_True_|_False_|_nil|)
|
486
486
|
*/
|
487
|
-
static VALUE str_writer_as_json(VALUE self) {
|
487
|
+
static VALUE str_writer_as_json(int argc, VALUE *argv, VALUE self) {
|
488
488
|
if (string_writer_optimized) {
|
489
489
|
return self;
|
490
490
|
}
|
@@ -515,5 +515,5 @@ void oj_string_writer_init(void) {
|
|
515
515
|
rb_define_method(oj_string_writer_class, "reset", str_writer_reset, 0);
|
516
516
|
rb_define_method(oj_string_writer_class, "to_s", str_writer_to_s, 0);
|
517
517
|
rb_define_method(oj_string_writer_class, "raw_json", str_writer_to_s, 0);
|
518
|
-
rb_define_method(oj_string_writer_class, "as_json", str_writer_as_json,
|
518
|
+
rb_define_method(oj_string_writer_class, "as_json", str_writer_as_json, -1);
|
519
519
|
}
|
data/lib/oj/version.rb
CHANGED
data/test/test_compat.rb
CHANGED
@@ -468,7 +468,7 @@ class CompatJuice < Minitest::Test
|
|
468
468
|
|
469
469
|
def test_arg_passing
|
470
470
|
json = Oj.to_json(Argy.new(), :max_nesting => 40)
|
471
|
-
|
471
|
+
assert_match(/.*max_nesting.*40.*/, json)
|
472
472
|
end
|
473
473
|
|
474
474
|
def test_max_nesting
|
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.8
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bigdecimal
|