diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-10-27 17:16:45 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-10-27 17:16:45 +0100 |
commit | c94ba8150a726da4a894cd8325ee682a3286ec9f (patch) | |
tree | d9a7c710747e8f9e491ca74edfa17c20a1f9020e /activerecord | |
parent | 9e2bb2caff2b6fd4712ca3db258b68a588a69e9a (diff) | |
download | rails-c94ba8150a726da4a894cd8325ee682a3286ec9f.tar.gz rails-c94ba8150a726da4a894cd8325ee682a3286ec9f.tar.bz2 rails-c94ba8150a726da4a894cd8325ee682a3286ec9f.zip |
Fixed that serialized strings should never be type-casted (i.e. turning "Yes" to a boolean)(Andreas Korth) [#857 state:committed]
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 5 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 2 | ||||
-rwxr-xr-x | activerecord/test/cases/base_test.rb | 6 |
3 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index fec110d569..06a290931c 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,3 +1,8 @@ +*2.2.1 [RC2 or 2.2 final]* + +* Fixed that serialized strings should never be type-casted (i.e. turning "Yes" to a boolean) #857 [Andreas Korth] + + *2.2.0 [RC1] (October 24th, 2008)* * Skip collection ids reader optimization if using :finder_sql [Jeremy Kemper] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index b89c8641aa..9c5690d3fd 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2938,7 +2938,7 @@ module ActiveRecord #:nodoc: end def object_from_yaml(string) - return string unless string.is_a?(String) + return string unless string.is_a?(String) && string =~ /^---/ YAML::load(string) rescue string end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index d512834237..da9f2742d8 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1429,6 +1429,12 @@ class BasicsTest < ActiveRecord::TestCase topic = Topic.create("content" => myobj).reload assert_equal(myobj, topic.content) end + + def test_serialized_string_attribute + myobj = "Yes" + topic = Topic.create("content" => myobj).reload + assert_equal(myobj, topic.content) + end def test_nil_serialized_attribute_with_class_constraint myobj = MyObject.new('value1', 'value2') |