aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG.md7
-rw-r--r--actionpack/lib/action_controller/metal/strong_parameters.rb5
-rw-r--r--actionpack/test/controller/required_params_test.rb6
3 files changed, 18 insertions, 0 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 999ac82d42..c6ea22a591 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Add `to_param` to `ActionController::Parameters` deprecations.
+
+ In the future `ActionController::Parameters` are discouraged from being used
+ in URLs without explicit whitelisting. Go through `to_h` to use `to_param`.
+
+ *Kir Shatrov*
+
* Fix nested multiple roots
The PR #20940 enabled the use of multiple roots with different constraints
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb
index d62e01d185..dea4657988 100644
--- a/actionpack/lib/action_controller/metal/strong_parameters.rb
+++ b/actionpack/lib/action_controller/metal/strong_parameters.rb
@@ -2,6 +2,7 @@ require "active_support/core_ext/hash/indifferent_access"
require "active_support/core_ext/hash/transform_values"
require "active_support/core_ext/array/wrap"
require "active_support/core_ext/string/filters"
+require "active_support/core_ext/object/to_query"
require "active_support/rescuable"
require "action_dispatch/http/upload"
require "rack/test"
@@ -619,6 +620,10 @@ module ActionController
end
end
+ # Undefine `to_param` such that it gets caught in the `method_missing`
+ # deprecation cycle below.
+ undef_method :to_param
+
def method_missing(method_sym, *args, &block)
if @parameters.respond_to?(method_sym)
message = <<-DEPRECATE.squish
diff --git a/actionpack/test/controller/required_params_test.rb b/actionpack/test/controller/required_params_test.rb
index 315d1ff3e8..9fa2b6dbb0 100644
--- a/actionpack/test/controller/required_params_test.rb
+++ b/actionpack/test/controller/required_params_test.rb
@@ -77,4 +77,10 @@ class ParametersRequireTest < ActiveSupport::TestCase
ActionController::Parameters.new(foo: "bar").merge!(bar: "foo")
end
end
+
+ test "to_query is not supported" do
+ assert_deprecated do
+ ActionController::Parameters.new(foo: "bar").to_param
+ end
+ end
end