diff options
author | Mike Mangino <mmangino@elevatedrails.com> | 2013-04-02 11:45:14 -0400 |
---|---|---|
committer | Mike Mangino <mmangino@elevatedrails.com> | 2013-04-02 11:45:14 -0400 |
commit | 1bf6b53aa4de9267dcca42382d841cf96e98b55f (patch) | |
tree | ee41fe697ec160226486bbcae7233107c3bd6300 /activerecord | |
parent | a4743960a09139c3bd4d72a8f3a72ade8f4add2f (diff) | |
download | rails-1bf6b53aa4de9267dcca42382d841cf96e98b55f.tar.gz rails-1bf6b53aa4de9267dcca42382d841cf96e98b55f.tar.bz2 rails-1bf6b53aa4de9267dcca42382d841cf96e98b55f.zip |
Remove all error masking when decoding serialized data fails?
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/coders/yaml_column.rb | 21 | ||||
-rw-r--r-- | activerecord/test/cases/coders/yaml_column_test.rb | 6 |
2 files changed, 12 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/coders/yaml_column.rb b/activerecord/lib/active_record/coders/yaml_column.rb index 1aa82f20d6..d3d7396c91 100644 --- a/activerecord/lib/active_record/coders/yaml_column.rb +++ b/activerecord/lib/active_record/coders/yaml_column.rb @@ -23,20 +23,15 @@ module ActiveRecord def load(yaml) return object_class.new if object_class != Object && yaml.nil? return yaml unless yaml.is_a?(String) && yaml =~ /^---/ - begin - obj = YAML.load(yaml) - - unless obj.is_a?(object_class) || obj.nil? - raise SerializationTypeMismatch, - "Attribute was supposed to be a #{object_class}, but was a #{obj.class}" - end - obj ||= object_class.new if object_class != Object - - obj - rescue ArgumentError , Psych::SyntaxError => e - raise if e.to_s =~ /undefined class/ - yaml + obj = YAML.load(yaml) + + unless obj.is_a?(object_class) || obj.nil? + raise SerializationTypeMismatch, + "Attribute was supposed to be a #{object_class}, but was a #{obj.class}" end + obj ||= object_class.new if object_class != Object + + obj end end end diff --git a/activerecord/test/cases/coders/yaml_column_test.rb b/activerecord/test/cases/coders/yaml_column_test.rb index 45e986c7b6..b72c54f97b 100644 --- a/activerecord/test/cases/coders/yaml_column_test.rb +++ b/activerecord/test/cases/coders/yaml_column_test.rb @@ -43,10 +43,12 @@ module ActiveRecord assert_equal [], coder.load([]) end - def test_load_swallows_yaml_exceptions + def test_load_doesnt_swallow_yaml_exceptions coder = YAMLColumn.new bad_yaml = '--- {' - assert_equal bad_yaml, coder.load(bad_yaml) + assert_raises(Psych::SyntaxError) do + coder.load(bad_yaml) + end end def test_load_doesnt_handle_undefined_class_or_module |