Skip to content

Commit eea1361

Browse files
Merge pull request #4582 from rubygems/restore_support_for_configuration_keys_with_dashes
Restore support for configuration keys with dashes (cherry picked from commit ece94c9)
1 parent fcbdfeb commit eea1361

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

bundler/lib/bundler/settings.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,20 @@ def load_config(config_file)
442442
valid_file = file.exist? && !file.size.zero?
443443
return {} unless valid_file
444444
require_relative "yaml_serializer"
445-
YAMLSerializer.load file.read
445+
YAMLSerializer.load(file.read).inject({}) do |config, (k, v)|
446+
new_k = k
447+
448+
if k.include?("-")
449+
Bundler.ui.warn "Your #{file} config includes `#{k}`, which contains the dash character (`-`).\n" \
450+
"This is deprecated, because configuration through `ENV` should be possible, but `ENV` keys cannot include dashes.\n" \
451+
"Please edit #{file} and replace any dashes in configuration keys with a triple underscore (`___`)."
452+
453+
new_k = k.gsub("-", "___")
454+
end
455+
456+
config[new_k] = v
457+
config
458+
end
446459
end
447460
end
448461

bundler/spec/bundler/settings_spec.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,26 @@
312312
describe "BUNDLE_ keys format" do
313313
let(:settings) { described_class.new(bundled_app(".bundle")) }
314314

315-
it "converts older keys without double dashes" do
315+
it "converts older keys without double underscore" do
316316
config("BUNDLE_MY__PERSONAL.RACK" => "~/Work/git/rack")
317317
expect(settings["my.personal.rack"]).to eq("~/Work/git/rack")
318318
end
319319

320-
it "converts older keys without trailing slashes and double dashes" do
320+
it "converts older keys without trailing slashes and double underscore" do
321321
config("BUNDLE_MIRROR__HTTPS://RUBYGEMS.ORG" => "http://rubygems-mirror.org")
322322
expect(settings["mirror.https://rubygems.org/"]).to eq("http://rubygems-mirror.org")
323323
end
324324

325+
it "converts older keys with dashes" do
326+
config("BUNDLE_MY-PERSONAL-SERVER__ORG" => "my-personal-server.org")
327+
expect(Bundler.ui).to receive(:warn).with(
328+
"Your #{bundled_app(".bundle/config")} config includes `BUNDLE_MY-PERSONAL-SERVER__ORG`, which contains the dash character (`-`).\n" \
329+
"This is deprecated, because configuration through `ENV` should be possible, but `ENV` keys cannot include dashes.\n" \
330+
"Please edit #{bundled_app(".bundle/config")} and replace any dashes in configuration keys with a triple underscore (`___`)."
331+
)
332+
expect(settings["my-personal-server.org"]).to eq("my-personal-server.org")
333+
end
334+
325335
it "reads newer keys format properly" do
326336
config("BUNDLE_MIRROR__HTTPS://RUBYGEMS__ORG/" => "http://rubygems-mirror.org")
327337
expect(settings["mirror.https://rubygems.org/"]).to eq("http://rubygems-mirror.org")

0 commit comments

Comments
 (0)