Permalink
Browse files

Remove all error masking when decoding serialized data fails?

  • Loading branch information...
1 parent a474396 commit 1bf6b53aa4de9267dcca42382d841cf96e98b55f @mmangino mmangino committed Apr 2, 2013
View
21 activerecord/lib/active_record/coders/yaml_column.rb
@@ -23,20 +23,15 @@ def dump(obj)
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
View
6 activerecord/test/cases/coders/yaml_column_test.rb
@@ -43,10 +43,12 @@ def test_load_handles_other_classes
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

0 comments on commit 1bf6b53

Please sign in to comment.