Skip to content

Commit

Permalink
Fixed Oj::Parser create_id size issue #931
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Dec 28, 2024
1 parent 6ecb749 commit ee07645
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 3.16.9 - 2024-12-28

- Fixed `Oj::Parser` create_id size issue #931.

- Changed parser to be more optimized (PR from @Watson1978)

## 3.16.8 - 2024-12-14

- Fixed StreamWriter to write to non-file IO thanks to @jscheid.
Expand Down
4 changes: 2 additions & 2 deletions ext/oj/usual.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,8 @@ static VALUE opt_create_id_set(ojParser p, VALUE value) {
rb_check_type(value, T_STRING);
size_t len = RSTRING_LEN(value);

if (1 << sizeof(d->create_id_len) <= len) {
rb_raise(rb_eArgError, "The create_id values is limited to %d bytes.", 1 << sizeof(d->create_id_len));
if (1 << (8 * sizeof(d->create_id_len)) <= len) {
rb_raise(rb_eArgError, "The create_id values is limited to %d bytes.", 1 << (8 * sizeof(d->create_id_len)));
}
d->create_id_len = (uint8_t)len;
d->create_id = str_dup(RSTRING_PTR(value), len);
Expand Down
2 changes: 1 addition & 1 deletion lib/oj/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Oj
# Current version of the module.
VERSION = '3.16.8'
VERSION = '3.16.9'
end
4 changes: 4 additions & 0 deletions test/test_parser_usual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ def test_create_id

doc = p.parse('{"a":true,"^":"UsualTest::MyClass","b":false}')
assert_equal('UsualTest::MyClass{a: true b: false}', doc.to_s)

p.create_id = 'class'
doc = p.parse('{"a":true,"class":"UsualTest::MyClass","b":false}')
assert_equal('UsualTest::MyClass{a: true b: false}', doc.to_s)
end

def test_missing_class
Expand Down

0 comments on commit ee07645

Please sign in to comment.