1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #9975 from mmangino/raise_when_attributes_cant_be_unserialized

Unserializing YAML attributes can silently fail in development mode
This commit is contained in:
Aaron Patterson 2013-04-02 09:38:36 -07:00
commit 22fee7cbe3
2 changed files with 19 additions and 13 deletions

View file

@ -23,7 +23,6 @@ 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?
@ -33,9 +32,6 @@ module ActiveRecord
obj ||= object_class.new if object_class != Object
obj
rescue ArgumentError, Psych::SyntaxError
yaml
end
end
end
end

View file

@ -43,10 +43,20 @@ 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
coder = YAMLColumn.new
missing_class_yaml = '--- !ruby/object:DoesNotExistAndShouldntEver {}\n'
assert_raises(ArgumentError) do
coder.load(missing_class_yaml)
end
end
end
end