Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop changes to a dupped ActionController::Parameters mutating the original #25735

Merged
merged 2 commits into from
Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions actionpack/lib/action_controller/metal/strong_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,11 @@ def hash_filter(params, filter)
end
end
end

def initialize_copy(source)
super
@parameters = source.instance_variable_get(:@parameters).dup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, we can just use @parameters = @parameters.dup, I think?

end
end

# == Strong \Parameters
Expand Down
25 changes: 25 additions & 0 deletions actionpack/test/controller/parameters/dup_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'abstract_unit'
require 'action_controller/metal/strong_parameters'

class ParametersDupTest < ActiveSupport::TestCase
setup do
ActionController::Parameters.permit_all_parameters = false

@params = ActionController::Parameters.new(
person: {
age: '32',
name: {
first: 'David',
last: 'Heinemeier Hansson'
},
addresses: [{city: 'Chicago', state: 'Illinois'}]
}
)
end

test "changes on a duplicate do not affect the original" do
dupped_params = @params.dup
dupped_params.delete(:person)
assert_not_equal @params, dupped_params
end
end