aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-27 15:14:47 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-27 15:17:47 -0300
commiteb6e3e34d766cd5d75258b1f4617c993f3347741 (patch)
treec8834197fe8292f8a79de898f922f7665e2436a9 /activerecord/lib
parenta87573d9e6610c72a93d4cc778e7703ca6d964e2 (diff)
parentc7802dccba69517083000261477f7e1d410e1cca (diff)
downloadrails-eb6e3e34d766cd5d75258b1f4617c993f3347741.tar.gz
rails-eb6e3e34d766cd5d75258b1f4617c993f3347741.tar.bz2
rails-eb6e3e34d766cd5d75258b1f4617c993f3347741.zip
Merge pull request #15788 from sgrif/sg-mutable-strings
Detect in-place modifications on Strings
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/type/string.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/type/string.rb b/activerecord/lib/active_record/type/string.rb
index 3b1554bd5a..14b03dcb2d 100644
--- a/activerecord/lib/active_record/type/string.rb
+++ b/activerecord/lib/active_record/type/string.rb
@@ -9,13 +9,28 @@ module ActiveRecord
true
end
+ def changed_in_place?(raw_old_value, new_value)
+ if new_value.is_a?(::String)
+ raw_old_value != new_value
+ end
+ end
+
+ def type_cast_for_database(value)
+ if value.is_a?(::String)
+ ::String.new(value)
+ else
+ super
+ end
+ end
+
private
def cast_value(value)
case value
when true then "1"
when false then "0"
- else value.to_s
+ # String.new is slightly faster than dup
+ else ::String.new(value.to_s)
end
end
end