Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/json/ext/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ static VALUE cState_init_copy(VALUE obj, VALUE orig)
{
JSON_Generator_State *objState, *origState;

rb_check_frozen(obj);
if (obj == orig) return obj;
GET_STATE_TO(obj, objState);
GET_STATE_TO(orig, origState);
Expand Down
1 change: 1 addition & 0 deletions java/src/json/ext/GeneratorState.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject arg0) {

@JRubyMethod
public IRubyObject initialize_copy(ThreadContext context, IRubyObject vOrig) {
checkFrozen();
Ruby runtime = context.runtime;
if (!(vOrig instanceof GeneratorState)) {
throw runtime.newTypeError(vOrig, getType());
Expand Down
13 changes: 13 additions & 0 deletions test/json/json_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,19 @@ def to_s
bignum.class.define_method(:to_s, original_to_s) if original_to_s
end

def test_initialize_copy_frozen_receiver
state = JSON::State.new(indent: 'original', max_nesting: 8).freeze
assert_raise(FrozenError) do
state.__send__(:initialize_copy, JSON::State.new(indent: 'replacement', max_nesting: 2))
end
assert_equal 'original', state.indent
assert_equal 8, state.max_nesting

assert_equal 'original', state.dup.indent
assert_predicate state.clone, :frozen?
assert_equal 'original', state.clone.indent
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
Expand Down
Loading