Skip to content

Commit

Permalink
Merge pull request #7574 from rubygems/deivid-rodriguez/windows-env
Browse files Browse the repository at this point in the history
Don't upcase Windows ENV before backing it up
  • Loading branch information
deivid-rodriguez committed Apr 25, 2024
2 parents 34d94ea + 1b6f232 commit fd08906
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
22 changes: 2 additions & 20 deletions bundler/lib/bundler/environment_preserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ class EnvironmentPreserver
BUNDLER_PREFIX = "BUNDLER_ORIG_"

def self.from_env
new(env_to_hash(ENV), BUNDLER_KEYS)
end

def self.env_to_hash(env)
to_hash = env.to_hash
return to_hash unless Gem.win_platform?

to_hash.each_with_object({}) {|(k,v), a| a[k.upcase] = v }
new(ENV.to_hash, BUNDLER_KEYS)
end

# @param env [Hash]
Expand All @@ -39,18 +32,7 @@ def initialize(env, keys)

# Replaces `ENV` with the bundler environment variables backed up
def replace_with_backup
unless Gem.win_platform?
ENV.replace(backup)
return
end

# Fallback logic for Windows below to workaround
# https://bugs.ruby-lang.org/issues/16798. Can be dropped once all
# supported rubies include the fix for that.

ENV.clear

backup.each {|k, v| ENV[k] = v }
ENV.replace(backup)
end

# @return [Hash]
Expand Down
18 changes: 18 additions & 0 deletions bundler/spec/runtime/inline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,22 @@ def confirm(msg, newline = nil)

expect(out).to include("Installing timeout 999")
end

it "does not upcase ENV" do
script <<-RUBY
require 'bundler/inline'
ENV['Test_Variable'] = 'value string'
puts("before: \#{ENV.each_key.select { |key| key.match?(/test_variable/i) }}")
gemfile do
source "#{file_uri_for(gem_repo1)}"
end
puts("after: \#{ENV.each_key.select { |key| key.match?(/test_variable/i) }}")
RUBY

expect(out).to include("before: [\"Test_Variable\"]")
expect(out).to include("after: [\"Test_Variable\"]")
end
end
6 changes: 3 additions & 3 deletions bundler/spec/runtime/with_unbundled_env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def run_bundler_script(env, script)
describe "Bundler.with_original_env" do
it "should set ENV to original_env in the block" do
expected = Bundler.original_env
actual = Bundler.with_original_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) }
actual = Bundler.with_original_env { ENV.to_hash }
expect(actual).to eq(expected)
end

Expand All @@ -157,7 +157,7 @@ def run_bundler_script(env, script)
expected = Bundler.unbundled_env

actual = Bundler.ui.silence do
Bundler.with_clean_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) }
Bundler.with_clean_env { ENV.to_hash }
end

expect(actual).to eq(expected)
Expand All @@ -175,7 +175,7 @@ def run_bundler_script(env, script)
describe "Bundler.with_unbundled_env" do
it "should set ENV to unbundled_env in the block" do
expected = Bundler.unbundled_env
actual = Bundler.with_unbundled_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) }
actual = Bundler.with_unbundled_env { ENV.to_hash }
expect(actual).to eq(expected)
end

Expand Down

0 comments on commit fd08906

Please sign in to comment.