Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore commented out keys in config file #7514

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions bundler/lib/bundler/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,19 @@ def load_config(config_file)
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
Expand Down
9 changes: 9 additions & 0 deletions bundler/spec/bundler/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@
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(
Expand Down