diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 172e89cffacfa..434bc555adacf 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,11 @@ +* Deprecate `Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality`. + + *Rafael Mendonça França* + +* Remove deprecated comparison between `ActionController::Parameters` and `Hash`. + + *Rafael Mendonça França* + * Remove deprecated constant `AbstractController::Helpers::MissingHelperError`. *Rafael Mendonça França* diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index f7819e57625e5..6afb4bdb2d20d 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -242,9 +242,21 @@ class Parameters # config.action_controller.always_permitted_parameters = %w( controller action format ) cattr_accessor :always_permitted_parameters, default: %w( controller action ) - cattr_accessor :allow_deprecated_parameters_hash_equality, default: true, instance_accessor: false - class << self + def allow_deprecated_parameters_hash_equality + ActionController.deprecator.warn <<-WARNING.squish + `Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality` is + deprecated and will be removed in Rails 7.3. + WARNING + end + + def allow_deprecated_parameters_hash_equality=(value) + ActionController.deprecator.warn <<-WARNING.squish + `Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality` + is deprecated and will be removed in Rails 7.3. + WARNING + end + def nested_attribute?(key, value) # :nodoc: /\A-?\d+\z/.match?(key) && (value.is_a?(Hash) || value.is_a?(Parameters)) end @@ -284,20 +296,7 @@ def ==(other) if other.respond_to?(:permitted?) permitted? == other.permitted? && parameters == other.parameters else - if self.class.allow_deprecated_parameters_hash_equality && Hash === other - ActionController.deprecator.warn <<-WARNING.squish - Comparing equality between `ActionController::Parameters` and a - `Hash` is deprecated and will be removed in Rails 7.2. Please only do - comparisons between instances of `ActionController::Parameters`. If - you need to compare to a hash, first convert it using - `ActionController::Parameters#new`. - To disable the deprecated behavior set - `Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality = false`. - WARNING - @parameters == other - else - super - end + super end end diff --git a/actionpack/test/controller/parameters/equality_test.rb b/actionpack/test/controller/parameters/equality_test.rb index f5078eb5491e0..153794a26ad48 100644 --- a/actionpack/test/controller/parameters/equality_test.rb +++ b/actionpack/test/controller/parameters/equality_test.rb @@ -19,36 +19,21 @@ class ParametersAccessorsTest < ActiveSupport::TestCase ) end - test "deprecated comparison works" do + test "parameters are not equal to the hash" do @hash = @params.each_pair.to_h - assert_deprecated(ActionController.deprecator) do - assert_equal @params, @hash - end - end - - test "deprecated comparison disabled" do - without_deprecated_params_hash_equality do - @hash = @params.each_pair.to_h - assert_not_deprecated(ActionController.deprecator) do - assert_not_equal @params, @hash - end - end + assert_not_equal @params, @hash end test "not eql? to equivalent hash" do @hash = {} @params = ActionController::Parameters.new(@hash) - assert_not_deprecated(ActionController.deprecator) do - assert_not @params.eql?(@hash) - end + assert_not @params.eql?(@hash) end test "not eql? to equivalent nested hash" do @params1 = ActionController::Parameters.new({ foo: {} }) @params2 = ActionController::Parameters.new({ foo: ActionController::Parameters.new({}) }) - assert_not_deprecated(ActionController.deprecator) do - assert_not @params1.eql?(@params2) - end + assert_not @params1.eql?(@params2) end test "not eql? when permitted is different" do @@ -62,26 +47,14 @@ class ParametersAccessorsTest < ActiveSupport::TestCase end test "has_value? converts hashes to parameters" do - assert_not_deprecated(ActionController.deprecator) do - params = ActionController::Parameters.new(foo: { bar: "baz" }) - assert params.has_value?("bar" => "baz") - params[:foo] # converts value to AC::Params - assert params.has_value?("bar" => "baz") - end + params = ActionController::Parameters.new(foo: { bar: "baz" }) + assert params.has_value?("bar" => "baz") + params[:foo] # converts value to AC::Params + assert params.has_value?("bar" => "baz") end test "has_value? works with parameters" do - without_deprecated_params_hash_equality do - params = ActionController::Parameters.new(foo: { bar: "baz" }) - assert params.has_value?(ActionController::Parameters.new("bar" => "baz")) - end + params = ActionController::Parameters.new(foo: { bar: "baz" }) + assert params.has_value?(ActionController::Parameters.new("bar" => "baz")) end - - private - def without_deprecated_params_hash_equality - ActionController::Parameters.allow_deprecated_parameters_hash_equality = false - yield - ensure - ActionController::Parameters.allow_deprecated_parameters_hash_equality = true - end end diff --git a/guides/source/7_2_release_notes.md b/guides/source/7_2_release_notes.md index ae348b72a45fd..bd3ee5ae01f8d 100644 --- a/guides/source/7_2_release_notes.md +++ b/guides/source/7_2_release_notes.md @@ -54,8 +54,12 @@ Please refer to the [Changelog][action-pack] for detailed changes. * Remove deprecated constant `AbstractController::Helpers::MissingHelperError`. +* Remove deprecated comparison between `ActionController::Parameters` and `Hash`. + ### Deprecations +* Deprecate `Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality`. + ### Notable changes Action View diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 2d81db1410258..632454b0bb8e9 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -60,7 +60,6 @@ Below are the default values associated with each target version. In cases of co #### Default Values for Target Version 7.1 -- [`config.action_controller.allow_deprecated_parameters_hash_equality`](#config-action-controller-allow-deprecated-parameters-hash-equality): `false` - [`config.action_dispatch.debug_exception_log_level`](#config-action-dispatch-debug-exception-log-level): `:error` - [`config.action_dispatch.default_headers`](#config-action-dispatch-default-headers): `{ "X-Frame-Options" => "SAMEORIGIN", "X-XSS-Protection" => "0", "X-Content-Type-Options" => "nosniff", "X-Permitted-Cross-Domain-Policies" => "none", "Referrer-Policy" => "strict-origin-when-cross-origin" }` - [`config.action_text.sanitizer_vendor`](#config-action-text-sanitizer-vendor): `Rails::HTML::Sanitizer.best_supported_vendor` @@ -1790,18 +1789,6 @@ The default value depends on the `config.load_defaults` target version: Configures the [`ParamsWrapper`](https://api.rubyonrails.org/classes/ActionController/ParamsWrapper.html). This can be called at the top level, or on individual controllers. -#### `config.action_controller.allow_deprecated_parameters_hash_equality` - -Controls behavior of `ActionController::Parameters#==` with `Hash` arguments. -Value of the setting determines whether an `ActionController::Parameters` instance is equal to an equivalent `Hash`. - -The default value depends on the `config.load_defaults` target version: - -| Starting with version | The default value is | -| --------------------- | -------------------- | -| (original) | `true` | -| 7.1 | `false` | - ### Configuring Action Dispatch #### `config.action_dispatch.cookies_serializer` diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index beef8821f04a3..c3bf037630f6d 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -316,10 +316,6 @@ def load_defaults(target_version) active_support.raise_on_invalid_cache_expiration_time = true end - if respond_to?(:action_controller) - action_controller.allow_deprecated_parameters_hash_equality = false - end - if defined?(Rails::HTML::Sanitizer) # nested ifs to avoid linter errors if respond_to?(:action_view) action_view.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor