• T
    Changes to a dupped `ActionController::Parameters` mutate the original · ba3dd5ca
    Tim Rogers 提交于
    When `ActionController::Parameters` is duplicated with `#dup`, it doesn't create a duplicate of the instance variables (e.g. `@parameters`) but rather maintains the reference (see <http://ruby-doc.org/core-2.3.1/Object.html>). Given that the parameters object is often manipulated as if it were a hash (e.g. with `#delete` and similar methods), this leads to unexpected behaviour, like the following:
    
    ```
    params = ActionController::Parameters.new(foo: "bar")
    duplicated_params = params.dup
    duplicated_params.delete(:foo)
    
    params == duplicated_params
    ```
    
    This fixes the bug by defining a private `#initialize_copy` method, used internally by `#dup`, which makes a copy of `@parameters`.
    ba3dd5ca
strong_parameters.rb 31.6 KB