Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
only parse specs as YAML if they look like YAML files, otherwise fall
Browse files Browse the repository at this point in the history
back to Ruby evaluation
  • Loading branch information
tenderlove committed Oct 24, 2012
1 parent e93a399 commit d1b6ced
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions lib/bundler.rb
Expand Up @@ -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
Expand All @@ -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?

Expand Down

5 comments on commit d1b6ced

@jroes
Copy link

@jroes jroes commented on d1b6ced Nov 7, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a pre-release on this?

Can't create a new Rails 4 project on Ruby 2 preview without it.

@rubys
Copy link

@rubys rubys commented on d1b6ced Nov 7, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just came to the same conclusion as @jroes. Apparently catching SyntaxError doesn't quite cut it any more, Psych::SyntaxError is what is raised. Even better: don't try it to parse it as YAML at all if it doesn't look like YAML...

@indirect
Copy link
Member

@indirect indirect commented on d1b6ced Nov 7, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rubys
Copy link

@rubys rubys commented on d1b6ced Nov 9, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a new ETA for 1.2.2?

@indirect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently wrestling with a failing spec that seems to only happen on ruby 1.9.2 and rubygems 1.7. Assuming I manage to get that resolved today, I will then push the new gem.

Please sign in to comment.