1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix HashWithIndifferentAccess#without bug

This commit is contained in:
Abraham Chan 2018-09-28 18:28:30 +10:00
parent 2ab0df00b6
commit b2ea831073
3 changed files with 18 additions and 0 deletions

View file

@ -1,3 +1,8 @@
* Fix bug where `#without` for `ActiveSupport::HashWithIndifferentAccess` would fail
with symbol arguments
*Abraham Chan*
* Treat `#delete_prefix`, `#delete_suffix` and `#unicode_normalize` results as non-`html_safe`.
Ensure safety of arguments for `#insert`, `#[]=` and `#replace` calls on `html_safe` Strings.

View file

@ -279,6 +279,8 @@ module ActiveSupport
super(convert_key(key))
end
alias_method :without, :except
def stringify_keys!; self end
def deep_stringify_keys!; self end
def stringify_keys; dup end

View file

@ -672,6 +672,17 @@ class HashWithIndifferentAccessTest < ActiveSupport::TestCase
assert_equal "bender", slice["login"]
end
def test_indifferent_without
original = { a: "x", b: "y", c: 10 }.with_indifferent_access
expected = { c: 10 }.with_indifferent_access
[["a", "b"], [:a, :b]].each do |keys|
# Should return a new hash without the given keys.
assert_equal expected, original.without(*keys), keys.inspect
assert_not_equal expected, original
end
end
def test_indifferent_extract
original = { :a => 1, "b" => 2, :c => 3, "d" => 4 }.with_indifferent_access
expected = { a: 1, b: 2 }.with_indifferent_access