oj 3.13.5 → 3.13.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -0
- data/RELEASE_NOTES.md +6 -0
- data/ext/oj/fast.c +6 -2
- data/ext/oj/intern.c +7 -1
- data/ext/oj/mimic_json.c +5 -15
- data/ext/oj/object.c +26 -45
- data/ext/oj/oj.c +108 -152
- data/ext/oj/oj.h +1 -0
- data/ext/oj/parse.c +9 -1
- data/ext/oj/parser.c +76 -28
- data/ext/oj/usual.c +19 -17
- data/lib/oj/version.rb +1 -1
- data/test/bar.rb +9 -28
- data/test/bug.rb +16 -0
- data/test/foo.rb +16 -9
- data/test/test_fast.rb +18 -7
- data/test/test_parser_usual.rb +9 -5
- metadata +7 -2
data/ext/oj/usual.c
CHANGED
@@ -39,7 +39,7 @@ typedef struct _col {
|
|
39
39
|
typedef union _key {
|
40
40
|
struct {
|
41
41
|
int16_t len;
|
42
|
-
char buf[
|
42
|
+
char buf[30];
|
43
43
|
};
|
44
44
|
struct {
|
45
45
|
int16_t xlen; // should be the same as len
|
@@ -209,21 +209,21 @@ static void push(ojParser p, VALUE v) {
|
|
209
209
|
static VALUE cache_key(ojParser p, Key kp) {
|
210
210
|
Delegate d = (Delegate)p->ctx;
|
211
211
|
|
212
|
-
if ((size_t)kp->len < sizeof(kp->buf)
|
212
|
+
if ((size_t)kp->len < sizeof(kp->buf)) {
|
213
213
|
return cache_intern(d->key_cache, kp->buf, kp->len);
|
214
214
|
}
|
215
215
|
return cache_intern(d->key_cache, kp->key, kp->len);
|
216
216
|
}
|
217
217
|
|
218
218
|
static VALUE str_key(ojParser p, Key kp) {
|
219
|
-
if ((size_t)kp->len < sizeof(kp->buf)
|
219
|
+
if ((size_t)kp->len < sizeof(kp->buf)) {
|
220
220
|
return rb_str_freeze(rb_utf8_str_new(kp->buf, kp->len));
|
221
221
|
}
|
222
222
|
return rb_str_freeze(rb_utf8_str_new(kp->key, kp->len));
|
223
223
|
}
|
224
224
|
|
225
225
|
static VALUE sym_key(ojParser p, Key kp) {
|
226
|
-
if ((size_t)kp->len < sizeof(kp->buf)
|
226
|
+
if ((size_t)kp->len < sizeof(kp->buf)) {
|
227
227
|
return rb_str_freeze(rb_str_intern(rb_utf8_str_new(kp->buf, kp->len)));
|
228
228
|
}
|
229
229
|
return rb_str_freeze(rb_str_intern(rb_utf8_str_new(kp->key, kp->len)));
|
@@ -232,7 +232,7 @@ static VALUE sym_key(ojParser p, Key kp) {
|
|
232
232
|
static ID get_attr_id(ojParser p, Key kp) {
|
233
233
|
Delegate d = (Delegate)p->ctx;
|
234
234
|
|
235
|
-
if ((size_t)kp->len < sizeof(kp->buf)
|
235
|
+
if ((size_t)kp->len < sizeof(kp->buf)) {
|
236
236
|
return (ID)cache_intern(d->attr_cache, kp->buf, kp->len);
|
237
237
|
}
|
238
238
|
return (ID)cache_intern(d->attr_cache, kp->key, kp->len);
|
@@ -253,7 +253,7 @@ static void push_key(ojParser p) {
|
|
253
253
|
d->kend = d->khead + cap;
|
254
254
|
}
|
255
255
|
d->ktail->len = klen;
|
256
|
-
if (klen
|
256
|
+
if (klen < sizeof(d->ktail->buf)) {
|
257
257
|
memcpy(d->ktail->buf, key, klen);
|
258
258
|
d->ktail->buf[klen] = '\0';
|
259
259
|
} else {
|
@@ -336,7 +336,7 @@ static void close_object(ojParser p) {
|
|
336
336
|
#if HAVE_RB_HASH_BULK_INSERT
|
337
337
|
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
338
338
|
*vp = d->get_key(p, kp);
|
339
|
-
if (sizeof(kp->buf)
|
339
|
+
if (sizeof(kp->buf) <= (size_t)kp->len) {
|
340
340
|
xfree(kp->key);
|
341
341
|
}
|
342
342
|
}
|
@@ -344,7 +344,7 @@ static void close_object(ojParser p) {
|
|
344
344
|
#else
|
345
345
|
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
346
346
|
rb_hash_aset(obj, d->get_key(p, kp), *(vp + 1));
|
347
|
-
if (sizeof(kp->buf)
|
347
|
+
if (sizeof(kp->buf) <= (size_t)kp->len) {
|
348
348
|
xfree(kp->key);
|
349
349
|
}
|
350
350
|
}
|
@@ -368,7 +368,7 @@ static void close_object_class(ojParser p) {
|
|
368
368
|
|
369
369
|
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
370
370
|
rb_funcall(obj, hset_id, 2, d->get_key(p, kp), *(vp + 1));
|
371
|
-
if (sizeof(kp->buf)
|
371
|
+
if (sizeof(kp->buf) <= (size_t)kp->len) {
|
372
372
|
xfree(kp->key);
|
373
373
|
}
|
374
374
|
}
|
@@ -396,7 +396,7 @@ static void close_object_create(ojParser p) {
|
|
396
396
|
#if HAVE_RB_HASH_BULK_INSERT
|
397
397
|
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
398
398
|
*vp = d->get_key(p, kp);
|
399
|
-
if (sizeof(kp->buf)
|
399
|
+
if (sizeof(kp->buf) <= (size_t)kp->len) {
|
400
400
|
xfree(kp->key);
|
401
401
|
}
|
402
402
|
}
|
@@ -404,7 +404,7 @@ static void close_object_create(ojParser p) {
|
|
404
404
|
#else
|
405
405
|
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
406
406
|
rb_hash_aset(obj, d->get_key(p, kp), *(vp + 1));
|
407
|
-
if (sizeof(kp->buf)
|
407
|
+
if (sizeof(kp->buf) <= (size_t)kp->len) {
|
408
408
|
xfree(kp->key);
|
409
409
|
}
|
410
410
|
}
|
@@ -413,7 +413,7 @@ static void close_object_create(ojParser p) {
|
|
413
413
|
obj = rb_class_new_instance(0, NULL, d->hash_class);
|
414
414
|
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
415
415
|
rb_funcall(obj, hset_id, 2, d->get_key(p, kp), *(vp + 1));
|
416
|
-
if (sizeof(kp->buf)
|
416
|
+
if (sizeof(kp->buf) <= (size_t)kp->len) {
|
417
417
|
xfree(kp->key);
|
418
418
|
}
|
419
419
|
}
|
@@ -428,7 +428,7 @@ static void close_object_create(ojParser p) {
|
|
428
428
|
#if HAVE_RB_HASH_BULK_INSERT
|
429
429
|
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
430
430
|
*vp = d->get_key(p, kp);
|
431
|
-
if (sizeof(kp->buf)
|
431
|
+
if (sizeof(kp->buf) <= (size_t)kp->len) {
|
432
432
|
xfree(kp->key);
|
433
433
|
}
|
434
434
|
}
|
@@ -436,7 +436,7 @@ static void close_object_create(ojParser p) {
|
|
436
436
|
#else
|
437
437
|
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
438
438
|
rb_hash_aset(arg, d->get_key(p, kp), *(vp + 1));
|
439
|
-
if (sizeof(kp->buf)
|
439
|
+
if (sizeof(kp->buf) <= (size_t)kp->len) {
|
440
440
|
xfree(kp->key);
|
441
441
|
}
|
442
442
|
}
|
@@ -446,7 +446,7 @@ static void close_object_create(ojParser p) {
|
|
446
446
|
obj = rb_class_new_instance(0, NULL, clas);
|
447
447
|
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
448
448
|
rb_ivar_set(obj, get_attr_id(p, kp), *(vp + 1));
|
449
|
-
if (sizeof(kp->buf)
|
449
|
+
if (sizeof(kp->buf) <= (size_t)kp->len) {
|
450
450
|
xfree(kp->key);
|
451
451
|
}
|
452
452
|
}
|
@@ -537,7 +537,7 @@ static void add_float_key(ojParser p) {
|
|
537
537
|
static void add_float_as_big(ojParser p) {
|
538
538
|
char buf[64];
|
539
539
|
|
540
|
-
// fails on ubuntu
|
540
|
+
// snprintf fails on ubuntu and macOS for long double
|
541
541
|
// snprintf(buf, sizeof(buf), "%Lg", p->num.dub);
|
542
542
|
sprintf(buf, "%Lg", p->num.dub);
|
543
543
|
push(p, rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(buf)));
|
@@ -546,7 +546,9 @@ static void add_float_as_big(ojParser p) {
|
|
546
546
|
static void add_float_as_big_key(ojParser p) {
|
547
547
|
char buf[64];
|
548
548
|
|
549
|
-
snprintf
|
549
|
+
// snprintf fails on ubuntu and macOS for long double
|
550
|
+
// snprintf(buf, sizeof(buf), "%Lg", p->num.dub);
|
551
|
+
sprintf(buf, "%Lg", p->num.dub);
|
550
552
|
push_key(p);
|
551
553
|
push2(p, rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(buf)));
|
552
554
|
}
|
data/lib/oj/version.rb
CHANGED
data/test/bar.rb
CHANGED
@@ -1,35 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
$: <<
|
4
|
-
|
5
|
-
|
6
|
-
$: << File.join($oj_dir, dir)
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'active_support'
|
10
|
-
require "active_support/json"
|
11
|
-
|
12
|
-
$s = "\u2014 & \n \u{1F618}"
|
13
|
-
|
14
|
-
=begin
|
15
|
-
def check(label)
|
16
|
-
puts "\n--- #{label} --------------------"
|
17
|
-
|
18
|
-
ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
|
19
|
-
puts "with standard_json == true: t.to_json - #{$t.to_json}"
|
20
|
-
ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
|
21
|
-
puts "with standard_json == false: t.to_json - #{$t.to_json}"
|
22
|
-
end
|
23
|
-
|
24
|
-
check('Before Oj')
|
25
|
-
=end
|
3
|
+
$: << '.'
|
4
|
+
$: << File.join(File.dirname(__FILE__), "../lib")
|
5
|
+
$: << File.join(File.dirname(__FILE__), "../ext")
|
26
6
|
|
27
7
|
require 'oj'
|
28
8
|
|
29
|
-
|
30
|
-
puts "ActiveSupport.encode(s) - #{ActiveSupport::JSON.encode($s)}"
|
9
|
+
json = %|[{"x12345678901234567890": true}]|
|
31
10
|
|
32
|
-
Oj.
|
33
|
-
|
11
|
+
p = Oj::Parser.new(:usual)
|
12
|
+
p.cache_keys = false
|
13
|
+
p.symbol_keys = true
|
14
|
+
x = p.parse(json)
|
34
15
|
|
35
|
-
|
16
|
+
pp x
|
data/test/bug.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$: << '.'
|
2
|
+
$: << File.join(File.dirname(__FILE__), "../lib")
|
3
|
+
$: << File.join(File.dirname(__FILE__), "../ext")
|
4
|
+
|
5
|
+
|
6
|
+
#require 'bundler/setup'
|
7
|
+
require 'oj'
|
8
|
+
require 'active_support'
|
9
|
+
require 'active_support/time_with_zone'
|
10
|
+
require 'tzinfo'
|
11
|
+
|
12
|
+
puts ActiveSupport::TimeWithZone
|
13
|
+
|
14
|
+
json = File.read('./bug.json')
|
15
|
+
|
16
|
+
Oj.load(json)
|
data/test/foo.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
$: << '.'
|
4
|
+
$: << File.join(File.dirname(__FILE__), "../lib")
|
5
|
+
$: << File.join(File.dirname(__FILE__), "../ext")
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
puts "cache_keys: #{Oj::default_options[:cache_keys]}"
|
11
|
-
puts "cache_str: #{Oj::default_options[:cache_str]}"
|
7
|
+
# require 'json'
|
8
|
+
require 'oj'
|
9
|
+
Oj.mimic_JSON
|
12
10
|
|
13
|
-
|
11
|
+
source = %( {"a": 1, "b": 2} )
|
12
|
+
puts "JSON.load, no symbolize => OK"
|
13
|
+
pp JSON.load( source )
|
14
|
+
puts "JSON.load, do symbolize => KO: keys are not symbols"
|
15
|
+
#pp JSON.load( source, nil, symbolize_names: true, create_additions: false )
|
16
|
+
pp JSON.load( source, nil, symbolize_names: true, create_additions: false )
|
17
|
+
puts "JSON.parse, no symbolize => OK"
|
18
|
+
pp JSON.parse( source )
|
19
|
+
puts "JSON.parse, do symbolize => OK"
|
20
|
+
pp JSON.parse( source, symbolize_names: true )
|
data/test/test_fast.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
$: << File.dirname(__FILE__)
|
5
5
|
|
@@ -36,6 +36,17 @@ class DocTest < Minitest::Test
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def test_leaf_of_existing_path
|
40
|
+
json = %{{"foo": 1, "fizz": true}}
|
41
|
+
Oj::Doc.open(json) do |doc|
|
42
|
+
%w(/foo/bar /fizz/bar).each do |path|
|
43
|
+
assert_nil(doc.fetch(path))
|
44
|
+
assert_equal(:default, doc.fetch(path, :default))
|
45
|
+
refute(doc.exists?(path))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
39
50
|
def test_true
|
40
51
|
json = %{true}
|
41
52
|
Oj::Doc.open(json) do |doc|
|
@@ -282,11 +293,11 @@ class DocTest < Minitest::Test
|
|
282
293
|
['/nothing', nil],
|
283
294
|
['/array/10', nil],
|
284
295
|
].each do |path,val|
|
285
|
-
|
286
|
-
|
287
|
-
|
296
|
+
if val.nil?
|
297
|
+
assert_nil(doc.fetch(path))
|
298
|
+
else
|
288
299
|
assert_equal(val, doc.fetch(path))
|
289
|
-
|
300
|
+
end
|
290
301
|
end
|
291
302
|
end
|
292
303
|
# verify empty hash and arrays return nil when a member is requested
|
@@ -313,7 +324,7 @@ class DocTest < Minitest::Test
|
|
313
324
|
end
|
314
325
|
end
|
315
326
|
|
316
|
-
def
|
327
|
+
def test_exists
|
317
328
|
Oj::Doc.open(@json1) do |doc|
|
318
329
|
[['/array/1', true],
|
319
330
|
['/array/1', true],
|
@@ -322,7 +333,7 @@ class DocTest < Minitest::Test
|
|
322
333
|
['/array/3', false],
|
323
334
|
['/nothing', false],
|
324
335
|
].each do |path,val|
|
325
|
-
assert_equal(val, doc.exists?(path))
|
336
|
+
assert_equal(val, doc.exists?(path), "failed for #{path.inspect}")
|
326
337
|
end
|
327
338
|
end
|
328
339
|
end
|
data/test/test_parser_usual.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# encoding:
|
2
|
+
# encoding: utf-8
|
3
3
|
|
4
4
|
$: << File.dirname(__FILE__)
|
5
5
|
|
@@ -73,9 +73,14 @@ class UsualTest < Minitest::Test
|
|
73
73
|
assert_equal({a: true, b: false}, doc)
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
76
|
+
def test_strings
|
77
77
|
p = Oj::Parser.new(:usual)
|
78
|
-
p.
|
78
|
+
doc = p.parse('{"ぴ": "", "ぴ ": "x", "c": "ぴーたー", "d": " ぴーたー "}')
|
79
|
+
assert_equal({'ぴ' => '', 'ぴ ' => 'x', 'c' => 'ぴーたー', 'd' => ' ぴーたー '}, doc)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_capacity
|
83
|
+
p = Oj::Parser.new(:usual, capacity: 1000)
|
79
84
|
assert_equal(4096, p.capacity)
|
80
85
|
p.capacity = 5000
|
81
86
|
assert_equal(5000, p.capacity)
|
@@ -181,8 +186,7 @@ class UsualTest < Minitest::Test
|
|
181
186
|
end
|
182
187
|
|
183
188
|
def test_missing_class
|
184
|
-
p = Oj::Parser.new(:usual)
|
185
|
-
p.create_id = '^'
|
189
|
+
p = Oj::Parser.new(:usual, create_id: '^')
|
186
190
|
json = '{"a":true,"^":"Auto","b":false}'
|
187
191
|
doc = p.parse(json)
|
188
192
|
assert_equal(Hash, doc.class)
|
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.13.
|
4
|
+
version: 3.13.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: 2021-
|
11
|
+
date: 2021-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -79,6 +79,9 @@ extensions:
|
|
79
79
|
- ext/oj/extconf.rb
|
80
80
|
extra_rdoc_files:
|
81
81
|
- README.md
|
82
|
+
- LICENSE
|
83
|
+
- CHANGELOG.md
|
84
|
+
- RELEASE_NOTES.md
|
82
85
|
- pages/Advanced.md
|
83
86
|
- pages/Compatibility.md
|
84
87
|
- pages/Custom.md
|
@@ -198,6 +201,7 @@ files:
|
|
198
201
|
- test/activesupport6/time_zone_test_helpers.rb
|
199
202
|
- test/bar.rb
|
200
203
|
- test/baz.rb
|
204
|
+
- test/bug.rb
|
201
205
|
- test/files.rb
|
202
206
|
- test/foo.rb
|
203
207
|
- test/helper.rb
|
@@ -329,6 +333,7 @@ test_files:
|
|
329
333
|
- test/activesupport6/time_zone_test_helpers.rb
|
330
334
|
- test/bar.rb
|
331
335
|
- test/baz.rb
|
336
|
+
- test/bug.rb
|
332
337
|
- test/files.rb
|
333
338
|
- test/foo.rb
|
334
339
|
- test/helper.rb
|