From 8de7df5b22e853f028e5a71b26d45a0ce7a2c0f4 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Wed, 12 Apr 2017 03:14:09 +0930 Subject: Don't freeze input strings See 34321e4a433bb7eef48fd743286601403f8f7d82 for background on ImmutableString vs String. Our String type cannot delegate typecasting to ImmutableString, because the latter freezes its input: duplicating the value after that gives us an unfrozen result, but still mutates the originally passed object. --- activemodel/lib/active_model/type/string.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/type/string.rb b/activemodel/lib/active_model/type/string.rb index c7e0208a5a..850cab962b 100644 --- a/activemodel/lib/active_model/type/string.rb +++ b/activemodel/lib/active_model/type/string.rb @@ -12,7 +12,12 @@ module ActiveModel private def cast_value(value) - ::String.new(super) + case value + when ::String then ::String.new(value) + when true then "t".freeze + when false then "f".freeze + else value.to_s + end end end end -- cgit v1.2.3