Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AC::Parameters#to_unsafe_h #18017

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
* Add `ActionController::Parameters#to_unsafe_h` to return an unfiltered
`Hash` representation of Parameters object. This is now a preferred way to
retrieve unfiltered parameters as we will stop inheriting `AC::Parameters`
object in Rails 5.0.

*Prem Sichanugrist*

* Restore handling of a bare `Authorization` header, without `token=`
prefix.

Expand Down
6 changes: 6 additions & 0 deletions actionpack/lib/action_controller/metal/strong_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ def to_h
end
end

# Returns an unsafe, unfiltered +Hash+ representation of this parameter.
def to_unsafe_h
to_hash
end
alias_method :to_unsafe_hash, :to_unsafe_h

# Convert all hashes in values into parameters, then yield each pair like
# the same way as <tt>Hash#each_pair</tt>
def each_pair(&block)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,10 @@ def assert_filtered_out(params, key)

assert_equal({ "controller" => "users", "action" => "create" }, params.to_h)
end

test "to_unsafe_h returns unfiltered params" do
assert @params.to_h.is_a? Hash
assert_not @params.to_h.is_a? ActionController::Parameters
assert_equal @params.to_hash, @params.to_unsafe_h
end
end