Skip to content

Commit

Permalink
Merge pull request #3877 from rreinhardt9/unbundled-env-rubyopts
Browse files Browse the repository at this point in the history
Look for absolute path when removing bundler/setup from RUBYOPT in Bundler.unbundled_env method

(cherry picked from commit 43ecbe8)
  • Loading branch information
deivid-rodriguez committed Oct 5, 2020
1 parent f31a383 commit 2fa6ab6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion bundler/lib/bundler.rb
Expand Up @@ -353,7 +353,10 @@ def unbundled_env
env.delete_if {|k, _| k[0, 7] == "BUNDLE_" }

if env.key?("RUBYOPT")
env["RUBYOPT"] = env["RUBYOPT"].sub "-rbundler/setup", ""
rubyopt = env["RUBYOPT"].split(" ")
rubyopt.delete("-r#{File.expand_path("bundler/setup", __dir__)}")
rubyopt.delete("-rbundler/setup")
env["RUBYOPT"] = rubyopt.join(" ")
end

if env.key?("RUBYLIB")
Expand Down
16 changes: 14 additions & 2 deletions bundler/spec/runtime/with_unbundled_env_spec.rb
Expand Up @@ -84,11 +84,23 @@ def run_bundler_script(env, script)
expect(last_command.stdboth).to include "false"
end

it "should remove '-rbundler/setup' from RUBYOPT" do
it "should remove absolute path to 'bundler/setup' from RUBYOPT even if it was present in original env" do
create_file("source.rb", <<-RUBY)
print #{modified_env}['RUBYOPT']
RUBY
ENV["RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}"
setup_require = "-r#{lib_dir}/bundler/setup"
ENV["BUNDLER_ORIG_RUBYOPT"] = "-W2 #{setup_require} #{ENV["RUBYOPT"]}"
simulate_bundler_version_when_missing_prerelease_default_gem_activation do
bundle_exec_ruby bundled_app("source.rb")
end
expect(last_command.stdboth).not_to include(setup_require)
end

it "should remove relative path to 'bundler/setup' from RUBYOPT even if it was present in original env" do
create_file("source.rb", <<-RUBY)
print #{modified_env}['RUBYOPT']
RUBY
ENV["BUNDLER_ORIG_RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}"
simulate_bundler_version_when_missing_prerelease_default_gem_activation do
bundle_exec_ruby bundled_app("source.rb")
end
Expand Down

0 comments on commit 2fa6ab6

Please sign in to comment.