Fix a compatibility issue with MultiJson.dump(obj, pretty: true)
Fix: https://github.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.
This commit is contained in:
parent
502bd6ba37
commit
293ad8a4e9
@ -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"); }
|
||||
else if (key == sym_as_json) { state->as_json = RTEST(val) ? rb_convert_type(val, T_DATA, "Proc", "to_proc") : Qfalse; }
|
||||
return ST_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -399,6 +399,11 @@ class JSONGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal :bar, state_hash[:foo]
|
||||
end
|
||||
|
||||
def test_json_state_to_h_roundtrip
|
||||
state = JSON.state.new
|
||||
assert_equal state.to_h, JSON.state.new(state.to_h).to_h
|
||||
end
|
||||
|
||||
def test_json_generate
|
||||
assert_raise JSON::GeneratorError do
|
||||
generate(["\xea"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user