oj 2.18.1 → 2.18.2
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 +16 -7
- data/ext/oj/val_stack.c +3 -0
- data/ext/oj/val_stack.h +1 -0
- data/lib/oj/version.rb +1 -1
- data/test/foo.rb +18 -9
- data/test/mem.rb +20 -0
- data/test/omit.rb +20 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e75fe6286b1a83b703bbb5fe4ef67620471ed85c
|
4
|
+
data.tar.gz: 11c1c0a4025e7230882265540158df6ca22c8324
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be67841c21694aeea3c687dac1e5e2c76a2069198dfc4e8edc9efc469a97489265e1814b4607740ee38814885868f6b7822cadd2ca5b5c1f3b058d2f318b951f
|
7
|
+
data.tar.gz: 53b40092ab955eed576c31a4c755583ba14ed6d1013363dbb6e8c256298c36bf0e67de9b9472be1ef1f0aa574735ba4ef417308beb283a43a698a9993ecd1d1a
|
data/ext/oj/dump.c
CHANGED
@@ -830,9 +830,10 @@ static int
|
|
830
830
|
hash_cb_strict(VALUE key, VALUE value, Out out) {
|
831
831
|
int depth = out->depth;
|
832
832
|
long size;
|
833
|
-
|
834
|
-
|
835
|
-
|
833
|
+
int rtype = rb_type(key);
|
834
|
+
|
835
|
+
if (rtype != T_STRING && rtype != T_SYMBOL) {
|
836
|
+
rb_raise(rb_eTypeError, "In :strict mode all Hash keys must be Strings or Symbols, not %s.\n", rb_class2name(rb_obj_class(key)));
|
836
837
|
}
|
837
838
|
if (out->omit_nil && Qnil == value) {
|
838
839
|
return ST_CONTINUE;
|
@@ -843,7 +844,11 @@ hash_cb_strict(VALUE key, VALUE value, Out out) {
|
|
843
844
|
grow(out, size);
|
844
845
|
}
|
845
846
|
fill_indent(out, depth);
|
846
|
-
|
847
|
+
if (rtype == T_STRING) {
|
848
|
+
dump_str_comp(key, out);
|
849
|
+
} else {
|
850
|
+
dump_sym_comp(key, out);
|
851
|
+
}
|
847
852
|
*out->cur++ = ':';
|
848
853
|
} else {
|
849
854
|
size = depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1;
|
@@ -861,7 +866,11 @@ hash_cb_strict(VALUE key, VALUE value, Out out) {
|
|
861
866
|
out->cur += out->opts->dump_opts.indent_size;
|
862
867
|
}
|
863
868
|
}
|
864
|
-
|
869
|
+
if (rtype == T_STRING) {
|
870
|
+
dump_str_comp(key, out);
|
871
|
+
} else {
|
872
|
+
dump_sym_comp(key, out);
|
873
|
+
}
|
865
874
|
size = out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2;
|
866
875
|
if (out->end - out->cur <= size) {
|
867
876
|
grow(out, size);
|
@@ -2307,8 +2316,8 @@ oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts) {
|
|
2307
2316
|
out.buf = buf;
|
2308
2317
|
out.end = buf + sizeof(buf) - BUFFER_EXTRA;
|
2309
2318
|
out.allocated = 0;
|
2310
|
-
oj_dump_obj_to_json(obj, copts, &out);
|
2311
2319
|
out.omit_nil = copts->dump_opts.omit_nil;
|
2320
|
+
oj_dump_obj_to_json(obj, copts, &out);
|
2312
2321
|
size = out.cur - out.buf;
|
2313
2322
|
if (oj_stringio_class == clas) {
|
2314
2323
|
rb_funcall(stream, oj_write_id, 1, rb_str_new(out.buf, size));
|
@@ -2536,8 +2545,8 @@ oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts) {
|
|
2536
2545
|
out.buf = buf;
|
2537
2546
|
out.end = buf + sizeof(buf) - BUFFER_EXTRA;
|
2538
2547
|
out.allocated = 0;
|
2539
|
-
oj_dump_leaf_to_json(leaf, copts, &out);
|
2540
2548
|
out.omit_nil = copts->dump_opts.omit_nil;
|
2549
|
+
oj_dump_leaf_to_json(leaf, copts, &out);
|
2541
2550
|
size = out.cur - out.buf;
|
2542
2551
|
if (0 == (f = fopen(path, "w"))) {
|
2543
2552
|
rb_raise(rb_eIOError, "%s\n", strerror(errno));
|
data/ext/oj/val_stack.c
CHANGED
data/ext/oj/val_stack.h
CHANGED
data/lib/oj/version.rb
CHANGED
data/test/foo.rb
CHANGED
@@ -4,16 +4,25 @@
|
|
4
4
|
$: << File.join(File.dirname(__FILE__), "../lib")
|
5
5
|
$: << File.join(File.dirname(__FILE__), "../ext")
|
6
6
|
|
7
|
+
require 'stringio'
|
7
8
|
require 'oj'
|
9
|
+
require 'jsonlint'
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
json = %|{
|
12
|
+
"id": "babrams",
|
13
|
+
"ssh_keys": [
|
14
|
+
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDMCKMvMJ2yb13pHLsIPqi2xHOBKFZKa8+FM1FUqNbIxKeq3LLw+4WiXLK60DxxS6hmOnXD+FcWNaykkGLyGQeYHxsHynsXo9BPaG/ewaAp5SDU/zAIAaex15s/zvo5l+5Pq9OwXYtFRmfezk3ImCx7SZ8sMmHiFHYD8d38XBlGX53kLSFm5HLEopEvSCRTUyTj+tPIspgYR6IvCTdXnamO9FT8Rkeqw+mqjX9sVTaLuuqwQZlRFRMslrrJbSfv+7XvyKsjOsmAlkEYRlpHbUCxUh2Hc5q2Wfm+acOHPkkUPX8kLeT2vW+Bd/9LlPi9BN0dbmazGPbf5kv02MRNQNeUrdRfdzRIOG4tUEv154msF7QdEuy9W4pv9p0z2rNOqOQEw9HPhMiAkftIVGnvvGRj9+jIARIVzV5gAfVm2DQbPJClr0tGNCfzHmndt6FddawubXFPvFNrKgdC38Ts0Jzl1F3aWGHT8UyURDbezrTGpxg+Cqq4YUXIZfrrqB8nzF8qK3eMW2Tcxdy2m+fFBzQeHlozBSP55dcdjekdQrcVcwkYux4jecJ9BU++DjWtMtY93LgVL5BnHixS4ybo7loCndYkpsI6ZZm9oLVxHsjeoaM9D9iYoN28LIlALBm/dnfCh92G/H40v/X25DMIvRqcfnE31gsOCJ85A29twSC+Cw== babrams@system76.servalws",
|
15
|
+
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCy3cbPekJYHAIa8J1fOr2iIqpx/7pl4giJYAG7HCfsunRRUq3dY1KhVw1BlmMGIDzNwcuNVIfBS5HS/wREqbHMXxbwAjWrMwUofWd09CTuKJZiyTLUC5pSQWKDXZrefH/Fwd7s+YKk1s78b49zkyDcHSnKxjN+5veinzeU+vaUF9duFAJ9OsL7kTDEzOUU0zJdSdUV0hH1lnljnvk8kXHLFl9sKS3iM2LRqW4B6wOc2RbXUnx+jwNaBsq1zd73F2q3Ta7GXdtW/q4oDYl3s72oW4ySL6TZfpLCiv/7txHicZiY1eqc591CON0k/Rh7eR7XsphwkUstoUPQcBuLqQPA529zBigD7A8PBmeHISxL2qirWjR2+PrEGn1b0yu8IHHz9ZgliX83Q4WpjXvJ3REj2jfM8hiFRV3lA/ovjQrmLLV8WUAZ8updcLE5mbhZzIsC4U/HKIJS02zoggHGHZauClwwcdBtIJnJqtP803yKNPO2sDudTpvEi8GZ8n6jSXo/N8nBVId2LZa5YY/g/v5kH0akn+/E3jXhw4CICNW8yICpeJO8dGYMOp3Bs9/cRK8QYomXqgpoFlvkgzT2h4Ie6lyRgNv5QnUyAnW43O5FdBnPk/XZ3LA462VU3uOfr0AQtEJzPccpFC6OCFYWdGwZQA/r1EZQES0yRfJLpx+uZQ== babrams@babrams-Serval-WS"
|
16
|
+
],
|
17
|
+
"htpasswd": "$1$i2xUX9a4$6LwYbCk4K6JErTDdaiZy50",
|
18
|
+
"groups": [
|
19
|
+
"devops"
|
20
|
+
],
|
21
|
+
"shell": "\/bin\/bash",
|
22
|
+
"comment": "Ben Abrams"
|
23
|
+
}|
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
json = Oj.dump(a, mode: :compat, use_to_json: true)
|
18
|
-
#=> NoMethodError: undefined method `to_hash' for #<A:0x007fae03de1dc8>
|
25
|
+
linter = JsonLint::Linter.new
|
26
|
+
linter.check_stream(StringIO.new(json))
|
19
27
|
|
28
|
+
puts "errors: #{linter.errors}"
|
data/test/mem.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$: << File.join(File.dirname(__FILE__), "../lib")
|
5
|
+
$: << File.join(File.dirname(__FILE__), "../ext")
|
6
|
+
|
7
|
+
require 'oj'
|
8
|
+
|
9
|
+
h = {
|
10
|
+
'a' => 1,
|
11
|
+
'b' => 2,
|
12
|
+
'c' => 3,
|
13
|
+
'd' => 4,
|
14
|
+
'e' => 5,
|
15
|
+
}
|
16
|
+
|
17
|
+
10000.times do
|
18
|
+
GC.start
|
19
|
+
Oj.dump(h)
|
20
|
+
end
|
data/test/omit.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$: << File.join(File.dirname(__FILE__), "../lib")
|
5
|
+
$: << File.join(File.dirname(__FILE__), "../ext")
|
6
|
+
|
7
|
+
require 'oj'
|
8
|
+
require 'stringio'
|
9
|
+
require 'parallel'
|
10
|
+
|
11
|
+
h = { a: 1, b: nil, c: 3 }
|
12
|
+
outputs = Parallel.map((0...30).to_a, in_process: 30) do |i|
|
13
|
+
io = StringIO.new('wb+')
|
14
|
+
Oj.to_stream(io, h, omit_nil: false)
|
15
|
+
io.string
|
16
|
+
end
|
17
|
+
|
18
|
+
outputs.each do |output|
|
19
|
+
puts output
|
20
|
+
end
|
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.18.
|
4
|
+
version: 2.18.2
|
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-01
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -128,7 +128,9 @@ files:
|
|
128
128
|
- test/isolated/test_mimic_rails_before.rb
|
129
129
|
- test/isolated/test_mimic_rails_datetime.rb
|
130
130
|
- test/isolated/test_mimic_redefine.rb
|
131
|
+
- test/mem.rb
|
131
132
|
- test/mod.rb
|
133
|
+
- test/omit.rb
|
132
134
|
- test/perf.rb
|
133
135
|
- test/perf_compat.rb
|
134
136
|
- test/perf_fast.rb
|
@@ -202,6 +204,7 @@ test_files:
|
|
202
204
|
- test/write_timebars.rb
|
203
205
|
- test/test_writer.rb
|
204
206
|
- test/russian.rb
|
207
|
+
- test/omit.rb
|
205
208
|
- test/test_gc.rb
|
206
209
|
- test/_test_active_mimic.rb
|
207
210
|
- test/test_serializer.rb
|
@@ -252,6 +255,7 @@ test_files:
|
|
252
255
|
- test/_test_mimic_rails.rb
|
253
256
|
- test/test_file.rb
|
254
257
|
- test/bug.rb
|
258
|
+
- test/mem.rb
|
255
259
|
- test/sample_json.rb
|
256
260
|
- test/test_debian.rb
|
257
261
|
- test/test_fast.rb
|