Skip to content

Commit a2a89b7

Browse files
Merge pull request #7574 from rubygems/deivid-rodriguez/windows-env
Don't upcase Windows ENV before backing it up (cherry picked from commit fd08906)
1 parent c1c2cb1 commit a2a89b7

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

bundler/lib/bundler/environment_preserver.rb

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@ class EnvironmentPreserver
1919
BUNDLER_PREFIX = "BUNDLER_ORIG_"
2020

2121
def self.from_env
22-
new(env_to_hash(ENV), BUNDLER_KEYS)
23-
end
24-
25-
def self.env_to_hash(env)
26-
to_hash = env.to_hash
27-
return to_hash unless Gem.win_platform?
28-
29-
to_hash.each_with_object({}) {|(k,v), a| a[k.upcase] = v }
22+
new(ENV.to_hash, BUNDLER_KEYS)
3023
end
3124

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

4033
# Replaces `ENV` with the bundler environment variables backed up
4134
def replace_with_backup
42-
unless Gem.win_platform?
43-
ENV.replace(backup)
44-
return
45-
end
46-
47-
# Fallback logic for Windows below to workaround
48-
# https://bugs.ruby-lang.org/issues/16798. Can be dropped once all
49-
# supported rubies include the fix for that.
50-
51-
ENV.clear
52-
53-
backup.each {|k, v| ENV[k] = v }
35+
ENV.replace(backup)
5436
end
5537

5638
# @return [Hash]

bundler/spec/runtime/inline_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,4 +638,22 @@ def confirm(msg, newline = nil)
638638

639639
expect(out).to include("Installing timeout 999")
640640
end
641+
642+
it "does not upcase ENV" do
643+
script <<-RUBY
644+
require 'bundler/inline'
645+
646+
ENV['Test_Variable'] = 'value string'
647+
puts("before: \#{ENV.each_key.select { |key| key.match?(/test_variable/i) }}")
648+
649+
gemfile do
650+
source "#{file_uri_for(gem_repo1)}"
651+
end
652+
653+
puts("after: \#{ENV.each_key.select { |key| key.match?(/test_variable/i) }}")
654+
RUBY
655+
656+
expect(out).to include("before: [\"Test_Variable\"]")
657+
expect(out).to include("after: [\"Test_Variable\"]")
658+
end
641659
end

bundler/spec/runtime/with_unbundled_env_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def run_bundler_script(env, script)
139139
describe "Bundler.with_original_env" do
140140
it "should set ENV to original_env in the block" do
141141
expected = Bundler.original_env
142-
actual = Bundler.with_original_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) }
142+
actual = Bundler.with_original_env { ENV.to_hash }
143143
expect(actual).to eq(expected)
144144
end
145145

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

159159
actual = Bundler.ui.silence do
160-
Bundler.with_clean_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) }
160+
Bundler.with_clean_env { ENV.to_hash }
161161
end
162162

163163
expect(actual).to eq(expected)
@@ -175,7 +175,7 @@ def run_bundler_script(env, script)
175175
describe "Bundler.with_unbundled_env" do
176176
it "should set ENV to unbundled_env in the block" do
177177
expected = Bundler.unbundled_env
178-
actual = Bundler.with_unbundled_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) }
178+
actual = Bundler.with_unbundled_env { ENV.to_hash }
179179
expect(actual).to eq(expected)
180180
end
181181

0 commit comments

Comments
 (0)