aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/strong_parameters.rb
diff options
context:
space:
mode:
authorTim Rogers <tim@gocardless.com>2016-07-08 17:48:21 +0100
committerTim Rogers <tim@gocardless.com>2016-07-08 17:48:25 +0100
commit96070595697477676ea051c19c2c951901302bed (patch)
treef51d42c1b9bc6cdc8a6a7bc633365e81ec410dad /actionpack/lib/action_controller/metal/strong_parameters.rb
parentba3dd5ca04e1b70afab964d32f9c0a6f9cace61c (diff)
downloadrails-96070595697477676ea051c19c2c951901302bed.tar.gz
rails-96070595697477676ea051c19c2c951901302bed.tar.bz2
rails-96070595697477676ea051c19c2c951901302bed.zip
Trust `Object#dup` in `ActionController::Parameters`, using `#initialize_copy` to manually duplicate the underlying parameters hash
It looks like `ActionController::Parameters#dup` is leftover from when the class inherited from `Hash`. We can just trust `#dup`, which already copies the `@permitted` instance variable (confirmed by tests). We still define a `#initialize_copy` to make `@parameters` a copy that can be mutated without affecting the original instance.
Diffstat (limited to 'actionpack/lib/action_controller/metal/strong_parameters.rb')
-rw-r--r--actionpack/lib/action_controller/metal/strong_parameters.rb16
1 files changed, 1 insertions, 15 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb
index fea04d98e0..26794c67b7 100644
--- a/actionpack/lib/action_controller/metal/strong_parameters.rb
+++ b/actionpack/lib/action_controller/metal/strong_parameters.rb
@@ -572,20 +572,6 @@ module ActionController
convert_value_to_parameters(@parameters.values_at(*keys))
end
- # Returns an exact copy of the <tt>ActionController::Parameters</tt>
- # instance. +permitted+ state is kept on the duped object.
- #
- # params = ActionController::Parameters.new(a: 1)
- # params.permit!
- # params.permitted? # => true
- # copy_params = params.dup # => <ActionController::Parameters {"a"=>1} permitted: true>
- # copy_params.permitted? # => true
- def dup
- super.tap do |duplicate|
- duplicate.permitted = @permitted
- end
- end
-
# Returns a new <tt>ActionController::Parameters</tt> with all keys from
# +other_hash+ merges into current hash.
def merge(other_hash)
@@ -786,7 +772,7 @@ module ActionController
def initialize_copy(source)
super
- @parameters = source.instance_variable_get(:@parameters).dup
+ @parameters = @parameters.dup
end
end