aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2015-01-16 21:56:26 +0000
committerAndrew White <pixeltrix@users.noreply.github.com>2015-01-16 21:56:26 +0000
commit0d019afcd538b9ecd425471b6db6d624e12897b3 (patch)
tree10dfef0c58891689370d625d1caaed7cf0c5cac6
parent23a80015a5e6b8a647344f44c62670b5fe02f521 (diff)
parent584931d749bfdd8553740bdcc6e4fef2c18ec523 (diff)
downloadrails-0d019afcd538b9ecd425471b6db6d624e12897b3.tar.gz
rails-0d019afcd538b9ecd425471b6db6d624e12897b3.tar.bz2
rails-0d019afcd538b9ecd425471b6db6d624e12897b3.zip
Merge pull request #18551 from aditya-kapoor/fix-frozen-hwia
Fix assignment for frozen value in HWIA
-rw-r--r--activesupport/CHANGELOG.md7
-rw-r--r--activesupport/lib/active_support/hash_with_indifferent_access.rb2
-rw-r--r--activesupport/test/hash_with_indifferent_access_test.rb7
3 files changed, 15 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index f6c236bc35..2caf0b27ee 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Duplicate frozen array when assigning it to a HashWithIndifferentAccess so
+ that it doesn't raise a `RuntimeError` when calling `map!` on it in `convert_value`.
+
+ Fixes #18550.
+
+ *Aditya Kapoor*
+
* Add missing time zone definitions for Russian Federation and sync them
with `zone.tab` file from tzdata version 2014j (latest).
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb
index 1468c62151..4f71f13971 100644
--- a/activesupport/lib/active_support/hash_with_indifferent_access.rb
+++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb
@@ -267,7 +267,7 @@ module ActiveSupport
value.nested_under_indifferent_access
end
elsif value.is_a?(Array)
- unless options[:for] == :assignment
+ if options[:for] != :assignment || value.frozen?
value = value.dup
end
value.map! { |e| convert_value(e, options) }
diff --git a/activesupport/test/hash_with_indifferent_access_test.rb b/activesupport/test/hash_with_indifferent_access_test.rb
index 843994147b..880457386e 100644
--- a/activesupport/test/hash_with_indifferent_access_test.rb
+++ b/activesupport/test/hash_with_indifferent_access_test.rb
@@ -7,4 +7,11 @@ class HashWithIndifferentAccessTest < ActiveSupport::TestCase
hash.reverse_merge! key: :new_value
assert_equal :old_value, hash[:key]
end
+
+ def test_frozen_value
+ value = [1, 2, 3].freeze
+ hash = {}.with_indifferent_access
+ hash[:key] = value
+ assert_equal hash[:key], value
+ end
end \ No newline at end of file