[rubygems/rubygems] Keep compatibility of past versions

https://github.com/rubygems/rubygems/commit/54b67fb251
This commit is contained in:
Hiroshi SHIBATA 2024-01-23 20:19:02 +09:00 коммит произвёл git
Родитель 1018dca09a
Коммит 723deec9cf
4 изменённых файлов: 27 добавлений и 5 удалений

Просмотреть файл

@ -56,9 +56,10 @@ module Bundler
last_hash = nil
last_empty_key = nil
str.split(/\r?\n/) do |line|
line = line.split("#", 2).first.strip if line.include?("#")
if match = HASH_REGEX.match(line)
indent, key, quote, val = match.captures
val = strip_comment(val)
convert_to_backward_compatible_key!(key)
depth = indent.size / 2
if quote.empty? && val.empty?
@ -73,6 +74,8 @@ module Bundler
end
elsif match = ARRAY_REGEX.match(line)
_, val = match.captures
val = strip_comment(val)
last_hash[last_empty_key] = [] unless last_hash[last_empty_key].is_a?(Array)
last_hash[last_empty_key].push(val)
@ -81,6 +84,14 @@ module Bundler
res
end
def strip_comment(val)
if val.include?("#") && !val.start_with?("#")
val.split("#", 2).first.strip
else
val
end
end
# for settings' keys
def convert_to_backward_compatible_key!(key)
key << "/" if /https?:/i.match?(key) && !%r{/\Z}.match?(key)

Просмотреть файл

@ -56,9 +56,10 @@ module Gem
last_hash = nil
last_empty_key = nil
str.split(/\r?\n/) do |line|
line = line.split("#", 2).first.strip if line.include?("#")
if match = HASH_REGEX.match(line)
indent, key, quote, val = match.captures
val = strip_comment(val)
convert_to_backward_compatible_key!(key)
depth = indent.size / 2
if quote.empty? && val.empty?
@ -73,6 +74,8 @@ module Gem
end
elsif match = ARRAY_REGEX.match(line)
_, val = match.captures
val = strip_comment(val)
last_hash[last_empty_key] = [] unless last_hash[last_empty_key].is_a?(Array)
last_hash[last_empty_key].push(val)
@ -81,6 +84,14 @@ module Gem
res
end
def strip_comment(val)
if val.include?("#") && !val.start_with?("#")
val.split("#", 2).first.strip
else
val
end
end
# for settings' keys
def convert_to_backward_compatible_key!(key)
key << "/" if /https?:/i.match?(key) && !%r{/\Z}.match?(key)

Просмотреть файл

@ -179,12 +179,12 @@ RSpec.describe Bundler::YAMLSerializer do
yaml = <<~YAML
---
foo: "bar"
buzz: # "foo"
buzz: "foo" # "bar"
YAML
hash = {
"foo" => "bar",
"buzz" => {},
"buzz" => "foo",
}
expect(serializer.load(yaml)).to eq(hash)

Просмотреть файл

@ -439,7 +439,7 @@ E
it "does not make bundler crash and ignores the configuration" do
bundle "config list --parseable"
expect(out).to be_empty
expect(out).to eq("#mirror.https://rails-assets.org/=http://localhost:9292")
expect(err).to be_empty
ruby(<<~RUBY)