Permalink
Browse files

Merge pull request #2130 from tenderlove/skipyaml

only parse specs as YAML if they look like YAML files
  • Loading branch information...
2 parents e93a399 + d1b6ced commit 1d3b19733a9020df628d7214281c50aeac367d3c @indirect indirect committed Oct 25, 2012
Showing with 24 additions and 16 deletions.
  1. +24 −16 lib/bundler.rb
View
40 lib/bundler.rb
@@ -291,24 +291,17 @@ def load_gemspec_uncached(file)
# Eval the gemspec from its parent directory
Dir.chdir(path.dirname.to_s) do
contents = File.read(path.basename.to_s)
- begin
- Gem::Specification.from_yaml(contents)
- # Raises ArgumentError if the file is not valid YAML
- rescue ArgumentError, SyntaxError, Gem::EndOfYAMLException, Gem::Exception
+
+ if contents =~ /\A---/ # try YAML
begin
- eval(contents, TOPLEVEL_BINDING, path.expand_path.to_s)
- rescue LoadError, SyntaxError => e
- original_line = e.backtrace.find { |line| line.include?(path.to_s) }
- msg = "There was a #{e.class} while evaluating #{path.basename}: \n#{e.message}"
- msg << " from\n #{original_line}" if original_line
- msg << "\n"
-
- if e.is_a?(LoadError) && RUBY_VERSION >= "1.9"
- msg << "\nDoes it try to require a relative path? That's been removed in Ruby 1.9."
- end
-
- raise GemspecError, msg
+ Gem::Specification.from_yaml(contents)
+ # Raises ArgumentError if the file is not valid YAML (on syck)
+ # Psych raises a Psych::SyntaxError
+ rescue ArgumentError, Psych::SyntaxError, Gem::EndOfYAMLException, Gem::Exception
+ eval_gemspec(path, contents)
end
+ else
+ eval_gemspec(path, contents)
end
end
end
@@ -319,6 +312,21 @@ def clear_gemspec_cache
private
+ def eval_gemspec(path, contents)
+ eval(contents, TOPLEVEL_BINDING, path.expand_path.to_s)
+ rescue LoadError, SyntaxError => e
+ original_line = e.backtrace.find { |line| line.include?(path.to_s) }
+ msg = "There was a #{e.class} while evaluating #{path.basename}: \n#{e.message}"
+ msg << " from\n #{original_line}" if original_line
+ msg << "\n"
+
+ if e.is_a?(LoadError) && RUBY_VERSION >= "1.9"
+ msg << "\nDoes it try to require a relative path? That's been removed in Ruby 1.9."
+ end
+
+ raise GemspecError, msg
+ end
+
def configure_gem_home_and_path
blank_home = ENV['GEM_HOME'].nil? || ENV['GEM_HOME'].empty?

0 comments on commit 1d3b197

Please sign in to comment.