Skip to content

Commit 1018dca

Browse files
hsbtmatzbot
authored andcommitted
[rubygems/rubygems] Skip to load commented out words
rubygems/rubygems@e6a9148ba2
1 parent 53d0cf4 commit 1018dca

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

lib/bundler/yaml_serializer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def load(str)
5656
last_hash = nil
5757
last_empty_key = nil
5858
str.split(/\r?\n/) do |line|
59+
line = line.split("#", 2).first.strip if line.include?("#")
5960
if match = HASH_REGEX.match(line)
6061
indent, key, quote, val = match.captures
6162
convert_to_backward_compatible_key!(key)

lib/rubygems/yaml_serializer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def load(str)
5656
last_hash = nil
5757
last_empty_key = nil
5858
str.split(/\r?\n/) do |line|
59+
line = line.split("#", 2).first.strip if line.include?("#")
5960
if match = HASH_REGEX.match(line)
6061
indent, key, quote, val = match.captures
6162
convert_to_backward_compatible_key!(key)

spec/bundler/bundler/yaml_serializer_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,21 @@
174174

175175
expect(serializer.load(yaml)).to eq(hash)
176176
end
177+
178+
it "skip commented out words" do
179+
yaml = <<~YAML
180+
---
181+
foo: "bar"
182+
buzz: # "foo"
183+
YAML
184+
185+
hash = {
186+
"foo" => "bar",
187+
"buzz" => {},
188+
}
189+
190+
expect(serializer.load(yaml)).to eq(hash)
191+
end
177192
end
178193

179194
describe "against yaml lib" do

spec/bundler/commands/config_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@
439439
it "does not make bundler crash and ignores the configuration" do
440440
bundle "config list --parseable"
441441

442-
expect(out).to eq("#mirror.https://rails-assets.org/=http://localhost:9292")
442+
expect(out).to be_empty
443443
expect(err).to be_empty
444444

445445
ruby(<<~RUBY)

0 commit comments

Comments
 (0)