Skip to content

Commit 43e42c1

Browse files
committed
Remove deprecated comparison between ActionController::Parameters and Hash
1 parent 87bc119 commit 43e42c1

File tree

6 files changed

+37
-70
lines changed

6 files changed

+37
-70
lines changed

actionpack/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* Deprecate `Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality`.
2+
3+
*Rafael Mendonça França*
4+
5+
* Remove deprecated comparison between `ActionController::Parameters` and `Hash`.
6+
7+
*Rafael Mendonça França*
8+
19
* Remove deprecated constant `AbstractController::Helpers::MissingHelperError`.
210

311
*Rafael Mendonça França*

actionpack/lib/action_controller/metal/strong_parameters.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,21 @@ class Parameters
242242
# config.action_controller.always_permitted_parameters = %w( controller action format )
243243
cattr_accessor :always_permitted_parameters, default: %w( controller action )
244244

245-
cattr_accessor :allow_deprecated_parameters_hash_equality, default: true, instance_accessor: false
246-
247245
class << self
246+
def allow_deprecated_parameters_hash_equality
247+
ActionController.deprecator.warn <<-WARNING.squish
248+
`Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality` is
249+
deprecated and will be removed in Rails 7.3.
250+
WARNING
251+
end
252+
253+
def allow_deprecated_parameters_hash_equality=(value)
254+
ActionController.deprecator.warn <<-WARNING.squish
255+
`Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality`
256+
is deprecated and will be removed in Rails 7.3.
257+
WARNING
258+
end
259+
248260
def nested_attribute?(key, value) # :nodoc:
249261
/\A-?\d+\z/.match?(key) && (value.is_a?(Hash) || value.is_a?(Parameters))
250262
end
@@ -284,20 +296,7 @@ def ==(other)
284296
if other.respond_to?(:permitted?)
285297
permitted? == other.permitted? && parameters == other.parameters
286298
else
287-
if self.class.allow_deprecated_parameters_hash_equality && Hash === other
288-
ActionController.deprecator.warn <<-WARNING.squish
289-
Comparing equality between `ActionController::Parameters` and a
290-
`Hash` is deprecated and will be removed in Rails 7.2. Please only do
291-
comparisons between instances of `ActionController::Parameters`. If
292-
you need to compare to a hash, first convert it using
293-
`ActionController::Parameters#new`.
294-
To disable the deprecated behavior set
295-
`Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality = false`.
296-
WARNING
297-
@parameters == other
298-
else
299-
super
300-
end
299+
super
301300
end
302301
end
303302

actionpack/test/controller/parameters/equality_test.rb

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,21 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
1919
)
2020
end
2121

22-
test "deprecated comparison works" do
22+
test "parameters are not equal to the hash" do
2323
@hash = @params.each_pair.to_h
24-
assert_deprecated(ActionController.deprecator) do
25-
assert_equal @params, @hash
26-
end
27-
end
28-
29-
test "deprecated comparison disabled" do
30-
without_deprecated_params_hash_equality do
31-
@hash = @params.each_pair.to_h
32-
assert_not_deprecated(ActionController.deprecator) do
33-
assert_not_equal @params, @hash
34-
end
35-
end
24+
assert_not_equal @params, @hash
3625
end
3726

3827
test "not eql? to equivalent hash" do
3928
@hash = {}
4029
@params = ActionController::Parameters.new(@hash)
41-
assert_not_deprecated(ActionController.deprecator) do
42-
assert_not @params.eql?(@hash)
43-
end
30+
assert_not @params.eql?(@hash)
4431
end
4532

4633
test "not eql? to equivalent nested hash" do
4734
@params1 = ActionController::Parameters.new({ foo: {} })
4835
@params2 = ActionController::Parameters.new({ foo: ActionController::Parameters.new({}) })
49-
assert_not_deprecated(ActionController.deprecator) do
50-
assert_not @params1.eql?(@params2)
51-
end
36+
assert_not @params1.eql?(@params2)
5237
end
5338

5439
test "not eql? when permitted is different" do
@@ -62,26 +47,14 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
6247
end
6348

6449
test "has_value? converts hashes to parameters" do
65-
assert_not_deprecated(ActionController.deprecator) do
66-
params = ActionController::Parameters.new(foo: { bar: "baz" })
67-
assert params.has_value?("bar" => "baz")
68-
params[:foo] # converts value to AC::Params
69-
assert params.has_value?("bar" => "baz")
70-
end
50+
params = ActionController::Parameters.new(foo: { bar: "baz" })
51+
assert params.has_value?("bar" => "baz")
52+
params[:foo] # converts value to AC::Params
53+
assert params.has_value?("bar" => "baz")
7154
end
7255

7356
test "has_value? works with parameters" do
74-
without_deprecated_params_hash_equality do
75-
params = ActionController::Parameters.new(foo: { bar: "baz" })
76-
assert params.has_value?(ActionController::Parameters.new("bar" => "baz"))
77-
end
57+
params = ActionController::Parameters.new(foo: { bar: "baz" })
58+
assert params.has_value?(ActionController::Parameters.new("bar" => "baz"))
7859
end
79-
80-
private
81-
def without_deprecated_params_hash_equality
82-
ActionController::Parameters.allow_deprecated_parameters_hash_equality = false
83-
yield
84-
ensure
85-
ActionController::Parameters.allow_deprecated_parameters_hash_equality = true
86-
end
8760
end

guides/source/7_2_release_notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ Please refer to the [Changelog][action-pack] for detailed changes.
5454

5555
* Remove deprecated constant `AbstractController::Helpers::MissingHelperError`.
5656

57+
* Remove deprecated comparison between `ActionController::Parameters` and `Hash`.
58+
5759
### Deprecations
5860

61+
* Deprecate `Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality`.
62+
5963
### Notable changes
6064

6165
Action View

guides/source/configuring.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ Below are the default values associated with each target version. In cases of co
6060

6161
#### Default Values for Target Version 7.1
6262

63-
- [`config.action_controller.allow_deprecated_parameters_hash_equality`](#config-action-controller-allow-deprecated-parameters-hash-equality): `false`
6463
- [`config.action_dispatch.debug_exception_log_level`](#config-action-dispatch-debug-exception-log-level): `:error`
6564
- [`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" }`
6665
- [`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:
17901789
Configures the [`ParamsWrapper`](https://api.rubyonrails.org/classes/ActionController/ParamsWrapper.html). This can be called at
17911790
the top level, or on individual controllers.
17921791

1793-
#### `config.action_controller.allow_deprecated_parameters_hash_equality`
1794-
1795-
Controls behavior of `ActionController::Parameters#==` with `Hash` arguments.
1796-
Value of the setting determines whether an `ActionController::Parameters` instance is equal to an equivalent `Hash`.
1797-
1798-
The default value depends on the `config.load_defaults` target version:
1799-
1800-
| Starting with version | The default value is |
1801-
| --------------------- | -------------------- |
1802-
| (original) | `true` |
1803-
| 7.1 | `false` |
1804-
18051792
### Configuring Action Dispatch
18061793

18071794
#### `config.action_dispatch.cookies_serializer`

railties/lib/rails/application/configuration.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,6 @@ def load_defaults(target_version)
316316
active_support.raise_on_invalid_cache_expiration_time = true
317317
end
318318

319-
if respond_to?(:action_controller)
320-
action_controller.allow_deprecated_parameters_hash_equality = false
321-
end
322-
323319
if defined?(Rails::HTML::Sanitizer) # nested ifs to avoid linter errors
324320
if respond_to?(:action_view)
325321
action_view.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor

0 commit comments

Comments
 (0)