diff --git a/lib/bundler.rb b/lib/bundler.rb index 7059830a46b..f16f944c5f1 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -236,12 +236,19 @@ def with_original_env def with_clean_env with_original_env do - ENV['MANPATH'] = ENV['BUNDLE_ORIG_MANPATH'] - ENV.delete_if { |k,_| k[0,7] == 'BUNDLE_' } - if ENV.has_key? 'RUBYOPT' - ENV['RUBYOPT'] = ENV['RUBYOPT'].sub '-rbundler/setup', '' - ENV['RUBYOPT'] = ENV['RUBYOPT'].sub "-I#{File.expand_path('..', __FILE__)}", '' + ENV["MANPATH"] = ENV["BUNDLE_ORIG_MANPATH"] + ENV.delete_if { |k,_| k[0,7] == "BUNDLE_" } + + if ENV.has_key?("RUBYOPT") + ENV["RUBYOPT"] = ENV["RUBYOPT"].sub "-rbundler/setup", "" + end + + if ENV.has_key?("RUBYLIB") + rubylib = ENV["RUBYLIB"].split(File::PATH_SEPARATOR) + rubylib.delete(File.expand_path("..", __FILE__)) + ENV["RUBYLIB"] = rubylib.join(File::PATH_SEPARATOR) end + yield end end