From ee0764546c537cd6424048a7dcee027c14431f1d Mon Sep 17 00:00:00 2001 From: Peter Ohler Date: Sat, 28 Dec 2024 15:28:32 -0500 Subject: [PATCH] Fixed Oj::Parser create_id size issue #931 --- CHANGELOG.md | 6 ++++++ ext/oj/usual.c | 4 ++-- lib/oj/version.rb | 2 +- test/test_parser_usual.rb | 4 ++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9a2d71d..538471ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/ext/oj/usual.c b/ext/oj/usual.c index d6296e0b..e00b7f6c 100644 --- a/ext/oj/usual.c +++ b/ext/oj/usual.c @@ -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); diff --git a/lib/oj/version.rb b/lib/oj/version.rb index 7cc1b368..803ba67e 100644 --- a/lib/oj/version.rb +++ b/lib/oj/version.rb @@ -1,4 +1,4 @@ module Oj # Current version of the module. - VERSION = '3.16.8' + VERSION = '3.16.9' end diff --git a/test/test_parser_usual.rb b/test/test_parser_usual.rb index e327e049..d181cce2 100755 --- a/test/test_parser_usual.rb +++ b/test/test_parser_usual.rb @@ -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