Skip to content

Commit 5f51d14

Browse files
committed
WIP2
1 parent 01e1dae commit 5f51d14

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/spring/application.rb

+9-6
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,19 @@ def run
134134
end
135135

136136
def with_env_vars(env)
137-
# Delete all env vars which are unchanged from before spring started
138-
original_env.each { |k, v| ENV.delete k if ENV[k] == v }
137+
# Allowed are keys currently not in ENV...
138+
allowed_keys = env.keys - ENV.keys
139+
# ...and ENV-keys whose values have not changed since the start of spring
140+
allowed_keys += original_env.select {|k, v| ENV[k] == v }.keys
141+
# never allowed:
142+
allowed_keys -= %w(RUBYOPT RUBY_ROOT BUNDLE_GEMFILE GEM_ROOT GEM_HOME GEM_PATH)
143+
allowed_keys.uniq!
139144

140-
changed_keys = env.keys - ENV.keys
141-
# Load in the current env vars, except those which *were* changed when spring started
142-
env.each { |k, v| ENV[k] ||= v }
145+
allowed_keys.each{|k| ENV[k] = env[k] }
143146

144147
yield
145148
ensure
146-
changed_keys.each do |k|
149+
allowed_keys.each do |k|
147150
original_env.has_key?(k) ? ENV[k] = original_env[k] : ENV.delete(k)
148151
end
149152
end

0 commit comments

Comments
 (0)