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

Commit

Permalink
Auto merge of #5391 - bundler:seg-ruby-version-requirement-valid, r=i…
Browse files Browse the repository at this point in the history
…ndirect

[RubyVersion] Ensure passed-in versions are valid during init

Closes #5380
  • Loading branch information
bundlerbot committed Feb 8, 2017
2 parents c0de8f6 + d4384e3 commit aa33ab2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/bundler/ruby_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def initialize(versions, patchlevel, engine, engine_version)
# must not be specified, or the engine version
# specified must match the version.

@versions = Array(versions)
@versions = Array(versions).map do |v|
op, v = Gem::Requirement.parse(v)
op == "=" ? v.to_s : "#{op} #{v}"
end

@gem_version = Gem::Requirement.create(@versions.first).requirements.first.last
@input_engine = engine && engine.to_s
@engine = engine && engine.to_s || "ruby"
Expand Down
20 changes: 20 additions & 0 deletions spec/install/gemfile/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,24 @@ def locked_ruby_version
expect(the_bundle).to include_gems "rack 1.0.0"
expect(locked_ruby_version.versions).to eq(["5100"])
end

it "allows requirements with trailing whitespace" do
install_gemfile! <<-G
source "file://#{gem_repo1}"
ruby "#{RUBY_VERSION}\\n \t\\n"
gem "rack"
G

expect(the_bundle).to include_gems "rack 1.0.0"
end

it "fails gracefully with malformed requirements" do
install_gemfile <<-G
source "file://#{gem_repo1}"
ruby ">= 0", "-.\\0"
gem "rack"
G

expect(out).to include("There was an error parsing") # i.e. DSL error, not error template
end
end

0 comments on commit aa33ab2

Please sign in to comment.