aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-10-15 09:55:30 -0700
committerSean Griffin <sean@seantheprogrammer.com>2015-10-15 09:55:30 -0700
commitd6919c524ab441429579a75af9335865d1b7d42a (patch)
tree3f349ceb1a91c9dce5cc8dedf8a5d0f2a5d8e6d1 /activemodel
parent34321e4a433bb7eef48fd743286601403f8f7d82 (diff)
downloadrails-d6919c524ab441429579a75af9335865d1b7d42a.tar.gz
rails-d6919c524ab441429579a75af9335865d1b7d42a.tar.bz2
rails-d6919c524ab441429579a75af9335865d1b7d42a.zip
All strings returned by `ImmutableString` should be frozen
I seriously don't even know why we handle booleans, but those strings should technically be frozen. Additionally, we don't need to actually check the class in the mutable string type, since the `cast_value` function will always return a string.
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/type/immutable_string.rb11
-rw-r--r--activemodel/lib/active_model/type/string.rb7
2 files changed, 7 insertions, 11 deletions
diff --git a/activemodel/lib/active_model/type/immutable_string.rb b/activemodel/lib/active_model/type/immutable_string.rb
index cfa4b3fb4b..20b8ca0cc4 100644
--- a/activemodel/lib/active_model/type/immutable_string.rb
+++ b/activemodel/lib/active_model/type/immutable_string.rb
@@ -17,11 +17,12 @@ module ActiveModel
private
def cast_value(value)
- case value
- when true then "t"
- when false then "f"
- else value.to_s.freeze
- end
+ result = case value
+ when true then "t"
+ when false then "f"
+ else value.to_s
+ end
+ result.freeze
end
end
end
diff --git a/activemodel/lib/active_model/type/string.rb b/activemodel/lib/active_model/type/string.rb
index 4c8dc15778..8a91410998 100644
--- a/activemodel/lib/active_model/type/string.rb
+++ b/activemodel/lib/active_model/type/string.rb
@@ -12,12 +12,7 @@ module ActiveModel
private
def cast_value(value)
- result = super
- if ::String === result
- ::String.new(result)
- else
- result
- end
+ ::String.new(super)
end
end
end