From dc06375c4fd471ed75da74e28154357a22c2d862 Mon Sep 17 00:00:00 2001 From: David Rodriguez Date: Wed, 13 Mar 2024 16:29:18 +0100 Subject: [PATCH] [rubygems/rubygems] Ignore commented out keys in config file https://github.com/rubygems/rubygems/commit/c4a8d2a930 --- lib/bundler/settings.rb | 17 ++++++++++------- spec/bundler/bundler/settings_spec.rb | 9 +++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index d84089ee41..379abfb24a 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -492,16 +492,19 @@ module Bundler valid_file = file.exist? && !file.size.zero? return {} unless valid_file serializer_class.load(file.read).inject({}) do |config, (k, v)| - if k.include?("-") - Bundler.ui.warn "Your #{file} config includes `#{k}`, which contains the dash character (`-`).\n" \ - "This is deprecated, because configuration through `ENV` should be possible, but `ENV` keys cannot include dashes.\n" \ - "Please edit #{file} and replace any dashes in configuration keys with a triple underscore (`___`)." + unless k.start_with?("#") + if k.include?("-") + Bundler.ui.warn "Your #{file} config includes `#{k}`, which contains the dash character (`-`).\n" \ + "This is deprecated, because configuration through `ENV` should be possible, but `ENV` keys cannot include dashes.\n" \ + "Please edit #{file} and replace any dashes in configuration keys with a triple underscore (`___`)." - # string hash keys are frozen - k = k.gsub("-", "___") + # string hash keys are frozen + k = k.gsub("-", "___") + end + + config[k] = v end - config[k] = v config end end diff --git a/spec/bundler/bundler/settings_spec.rb b/spec/bundler/bundler/settings_spec.rb index 469af2b8c6..634e0faf91 100644 --- a/spec/bundler/bundler/settings_spec.rb +++ b/spec/bundler/bundler/settings_spec.rb @@ -319,6 +319,15 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow expect(settings["mirror.https://rubygems.org/"]).to eq("http://rubygems-mirror.org") end + it "ignores commented out keys" do + create_file bundled_app(".bundle/config"), <<~C + # BUNDLE_MY-PERSONAL-SERVER__ORG: my-personal-server.org + C + + expect(Bundler.ui).not_to receive(:warn) + expect(settings.all).to be_empty + end + it "converts older keys with dashes" do config("BUNDLE_MY-PERSONAL-SERVER__ORG" => "my-personal-server.org") expect(Bundler.ui).to receive(:warn).with(