Skip to content

Commit ee07645

Browse files
committed
Fixed Oj::Parser create_id size issue #931
1 parent 6ecb749 commit ee07645

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

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+
39
## 3.16.8 - 2024-12-14
410

511
- Fixed StreamWriter to write to non-file IO thanks to @jscheid.

ext/oj/usual.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,8 @@ static VALUE opt_create_id_set(ojParser p, VALUE value) {
834834
rb_check_type(value, T_STRING);
835835
size_t len = RSTRING_LEN(value);
836836

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)));
839839
}
840840
d->create_id_len = (uint8_t)len;
841841
d->create_id = str_dup(RSTRING_PTR(value), len);

lib/oj/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module Oj
22
# Current version of the module.
3-
VERSION = '3.16.8'
3+
VERSION = '3.16.9'
44
end

test/test_parser_usual.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ def test_create_id
217217

218218
doc = p.parse('{"a":true,"^":"UsualTest::MyClass","b":false}')
219219
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)
220224
end
221225

222226
def test_missing_class

0 commit comments

Comments
 (0)