summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2025-04-27 11:10:00 +0200
committerJean Boussier <[email protected]>2025-04-30 08:12:41 +0200
commit5566a7f7402197002a8d12420230f32d5fff727b ()
tree7f7910933769906d02c076bd0200af8cc8dd5897
parent1103611600fd64569b450619bca68f7ef00dddfb (diff)
[ruby/json] Handle non-string keys returning immediate values via `to_s`
We can't directly call `RBASIC_CLASS` as the return value of `to_s` may be an immediate. https://.com/ruby/json/commit/12dc394d11
-rw-r--r--ext/json/generator/generator.c17
-rwxr-xr-xtest/json/json_generator_test.rb16
2 files changed, 32 insertions, 1 deletions
@@ -789,6 +789,21 @@ struct hash_foreach_arg {
int iter;
};
static int
json_object_i(VALUE key, VALUE val, VALUE _arg)
{
@@ -817,7 +832,7 @@ json_object_i(VALUE key, VALUE val, VALUE _arg)
if (RB_LIKELY(RBASIC_CLASS(key) == rb_cString)) {
key_to_s = key;
} else {
- key_to_s = rb_funcall(key, i_to_s, 0);
}
break;
case T_SYMBOL:
@@ -605,6 +605,22 @@ class JSONGeneratorTest < Test::Unit::TestCase
assert_equal '{"JSONGeneratorTest::StringWithToS#to_s":1}', JSON.generate(StringWithToS.new => 1)
end
if defined?(JSON::Ext::Generator) and RUBY_PLATFORM != "java"
def test_valid_utf8_in_different_encoding
utf8_string = "€™"