Skip to content

Commit 723deec

Browse files
hsbtmatzbot
authored andcommitted
[rubygems/rubygems] Keep compatibility of past versions
rubygems/rubygems@54b67fb251
1 parent 1018dca commit 723deec

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

lib/bundler/yaml_serializer.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ 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?("#")
6059
if match = HASH_REGEX.match(line)
6160
indent, key, quote, val = match.captures
61+
val = strip_comment(val)
62+
6263
convert_to_backward_compatible_key!(key)
6364
depth = indent.size / 2
6465
if quote.empty? && val.empty?
@@ -73,6 +74,8 @@ def load(str)
7374
end
7475
elsif match = ARRAY_REGEX.match(line)
7576
_, val = match.captures
77+
val = strip_comment(val)
78+
7679
last_hash[last_empty_key] = [] unless last_hash[last_empty_key].is_a?(Array)
7780

7881
last_hash[last_empty_key].push(val)
@@ -81,6 +84,14 @@ def load(str)
8184
res
8285
end
8386

87+
def strip_comment(val)
88+
if val.include?("#") && !val.start_with?("#")
89+
val.split("#", 2).first.strip
90+
else
91+
val
92+
end
93+
end
94+
8495
# for settings' keys
8596
def convert_to_backward_compatible_key!(key)
8697
key << "/" if /https?:/i.match?(key) && !%r{/\Z}.match?(key)

lib/rubygems/yaml_serializer.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ 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?("#")
6059
if match = HASH_REGEX.match(line)
6160
indent, key, quote, val = match.captures
61+
val = strip_comment(val)
62+
6263
convert_to_backward_compatible_key!(key)
6364
depth = indent.size / 2
6465
if quote.empty? && val.empty?
@@ -73,6 +74,8 @@ def load(str)
7374
end
7475
elsif match = ARRAY_REGEX.match(line)
7576
_, val = match.captures
77+
val = strip_comment(val)
78+
7679
last_hash[last_empty_key] = [] unless last_hash[last_empty_key].is_a?(Array)
7780

7881
last_hash[last_empty_key].push(val)
@@ -81,6 +84,14 @@ def load(str)
8184
res
8285
end
8386

87+
def strip_comment(val)
88+
if val.include?("#") && !val.start_with?("#")
89+
val.split("#", 2).first.strip
90+
else
91+
val
92+
end
93+
end
94+
8495
# for settings' keys
8596
def convert_to_backward_compatible_key!(key)
8697
key << "/" if /https?:/i.match?(key) && !%r{/\Z}.match?(key)

spec/bundler/bundler/yaml_serializer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@
179179
yaml = <<~YAML
180180
---
181181
foo: "bar"
182-
buzz: # "foo"
182+
buzz: "foo" # "bar"
183183
YAML
184184

185185
hash = {
186186
"foo" => "bar",
187-
"buzz" => {},
187+
"buzz" => "foo",
188188
}
189189

190190
expect(serializer.load(yaml)).to eq(hash)

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 be_empty
442+
expect(out).to eq("#mirror.https://rails-assets.org/=http://localhost:9292")
443443
expect(err).to be_empty
444444

445445
ruby(<<~RUBY)

0 commit comments

Comments
 (0)