Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Psych errors with poor yaml formatting are proxied. Fixes #2645, #2731

  • Loading branch information...
commit e46c4f1c12b4cb6728a2c1b4318f65df08594735 1 parent 3afa90d
@tenderlove tenderlove authored
View
5 activerecord/CHANGELOG
@@ -1,3 +1,8 @@
+*Rails 3.1.1 (unreleased)*
+
+* Psych errors with poor yaml formatting are proxied. Fixes GH #2645 and
+ GH #2731
+
*Rails 3.1.0 (August 30, 2011)*
* Add a proxy_association method to association proxies, which can be called by association
View
8 activerecord/lib/active_record/fixtures.rb
@@ -715,9 +715,15 @@ def yaml_fixtures_key(path)
File.basename(@fixture_path).split(".").first
end
+ RESCUE_ERRORS = [ ArgumentError ]
+
+ if defined?(Psych) && defined?(Psych::SyntaxError)
+ RESCUE_ERRORS << Psych::SyntaxError
+ end
+
def parse_yaml_string(fixture_content)
YAML::load(erb_render(fixture_content))
- rescue => error
+ rescue *RESCUE_ERRORS => error
raise Fixture::FormatError, "a YAML error occurred parsing #{yaml_file_path}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n #{error.class}: #{error}"
end
View
16 activerecord/test/cases/fixtures_test.rb
@@ -20,6 +20,7 @@
require 'models/admin'
require 'models/admin/account'
require 'models/admin/user'
+require 'tempfile'
class FixturesTest < ActiveRecord::TestCase
self.use_instantiated_fixtures = true
@@ -45,6 +46,21 @@ def test_clean_fixtures
end
end
+ def test_broken_yaml_exception
+ badyaml = Tempfile.new ['foo', '.yml']
+ badyaml.write 'a: !ruby.yaml.org,2002:str |\nfoo'
+ badyaml.flush
+
+ dir = File.dirname badyaml.path
+ name =File.basename badyaml.path, '.yml'
+ assert_raises(ActiveRecord::Fixture::FormatError) do
+ ActiveRecord::Fixtures.create_fixtures(dir, name)
+ end
+ ensure
+ badyaml.close
+ badyaml.unlink
+ end
+
def test_create_fixtures
ActiveRecord::Fixtures.create_fixtures(FIXTURES_ROOT, "parrots")
assert Parrot.find_by_name('Curious George'), 'George is in the database'
Please sign in to comment.
Something went wrong with that request. Please try again.