Skip to content

Commit

Permalink
Raise an exception when unserialization fails due to a missing class
Browse files Browse the repository at this point in the history
  • Loading branch information
mmangino committed Mar 28, 2013
1 parent 51ba66b commit a474396
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion activerecord/lib/active_record/coders/yaml_column.rb
Expand Up @@ -33,7 +33,8 @@ def load(yaml)
obj ||= object_class.new if object_class != Object

obj
rescue ArgumentError, Psych::SyntaxError
rescue ArgumentError , Psych::SyntaxError => e
raise if e.to_s =~ /undefined class/
yaml
end
end
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/cases/coders/yaml_column_test.rb
Expand Up @@ -48,6 +48,14 @@ def test_load_swallows_yaml_exceptions
bad_yaml = '--- {'
assert_equal bad_yaml, coder.load(bad_yaml)
end

def test_load_doesnt_handle_undefined_class_or_module
coder = YAMLColumn.new
missing_class_yaml = '--- !ruby/object:DoesNotExistAndShouldntEver {}\n'
assert_raises(ArgumentError) do
coder.load(missing_class_yaml)
end
end
end
end
end

0 comments on commit a474396

Please sign in to comment.