Repository navigation
Conversation
When the current scope is empty, `merge!` and `array!` (without a block)
stored the caller's hash or array as the builder's attributes. Later
writes like `json.name ...` or `json.child! { ... }` then mutated that
object in place, so e.g. a shared defaults hash merged inside a block
picked up keys from the template, and frozen values raised FrozenError.
Since 2.15.0 this also broke `json.array!` with no collection (or nil)
followed by `json.child!`, because the frozen internal empty array was
stored directly.
Store a shallow copy when an external value would be adopted as is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the current scope is empty,
merge!andarray!(without a block) adopted the caller's hash or array — or the frozen internalEMPTY_ARRAY— as@attributes. Later writes likejson.name ...orjson.child! { ... }then mutated that object in place (so a shared defaults hash picked up keys from the template) or raisedFrozenError.This is a regression since 2.15.0:
json.array!with no collection (ornil) followed byjson.child!stores the frozen empty array and fails.Changes
_merge_external_values, which shallow-copies when the merge result would be the caller's object (orEMPTY_ARRAY).merge!, andarray!+child!after an empty / nil collection.Test plan
bin/test test/jbuilder_test.rb