summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2025-02-10 21:09:35 +0100
committerHiroshi SHIBATA <[email protected]>2025-02-12 13:15:01 +0900
commit293ad8a4e974e3dffc1419b37c15748f02b1481e ()
treea3e6c430a90b0069413e357e52fac047aba121c7
parent502bd6ba37b1820f5f5a0fe6bc9820797fddc0d6 (diff)
Fix a compatibility issue with `MultiJson.dump(obj, pretty: true)`
Fix: https://.com/ruby/json/issues/748 `MultiJson` pass `State#to_h` as options, and the `as_json` property defaults to `false` but `false` wasn't accepted by the constructor.
-rw-r--r--ext/json/generator/generator.c2
-rwxr-xr-xtest/json/json_generator_test.rb5
2 files changed, 6 insertions, 1 deletions
@@ -1626,7 +1626,7 @@ static int configure_state_i(VALUE key, VALUE val, VALUE _arg)
else if (key == sym_script_safe) { state->script_safe = RTEST(val); }
else if (key == sym_escape_slash) { state->script_safe = RTEST(val); }
else if (key == sym_strict) { state->strict = RTEST(val); }
- else if (key == sym_as_json) { state->as_json = rb_convert_type(val, T_DATA, "Proc", "to_proc"); }
return ST_CONTINUE;
}
@@ -399,6 +399,11 @@ class JSONGeneratorTest < Test::Unit::TestCase
assert_equal :bar, state_hash[:foo]
end
def test_json_generate
assert_raise JSON::GeneratorError do
generate(["\xea"])