aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-04-12 03:14:09 +0930
committerMatthew Draper <matthew@trebex.net>2017-04-12 03:14:09 +0930
commit8de7df5b22e853f028e5a71b26d45a0ce7a2c0f4 (patch)
tree817c7966183f31e2e9d004e35489a09a8a5bed91 /activemodel/lib
parent24ac36be7150f97ac0a61cf7cbe7d212097ef1a6 (diff)
downloadrails-8de7df5b22e853f028e5a71b26d45a0ce7a2c0f4.tar.gz
rails-8de7df5b22e853f028e5a71b26d45a0ce7a2c0f4.tar.bz2
rails-8de7df5b22e853f028e5a71b26d45a0ce7a2c0f4.zip
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.
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/type/string.rb7
1 files changed, 6 insertions, 1 deletions
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