[rubygems/rubygems] Keep compatibility of past versions
https://github.com/rubygems/rubygems/commit/54b67fb251
This commit is contained in:
parent
1018dca09a
commit
723deec9cf
@ -56,9 +56,10 @@ module Bundler
|
|||||||
last_hash = nil
|
last_hash = nil
|
||||||
last_empty_key = nil
|
last_empty_key = nil
|
||||||
str.split(/\r?\n/) do |line|
|
str.split(/\r?\n/) do |line|
|
||||||
line = line.split("#", 2).first.strip if line.include?("#")
|
|
||||||
if match = HASH_REGEX.match(line)
|
if match = HASH_REGEX.match(line)
|
||||||
indent, key, quote, val = match.captures
|
indent, key, quote, val = match.captures
|
||||||
|
val = strip_comment(val)
|
||||||
|
|
||||||
convert_to_backward_compatible_key!(key)
|
convert_to_backward_compatible_key!(key)
|
||||||
depth = indent.size / 2
|
depth = indent.size / 2
|
||||||
if quote.empty? && val.empty?
|
if quote.empty? && val.empty?
|
||||||
@ -73,6 +74,8 @@ module Bundler
|
|||||||
end
|
end
|
||||||
elsif match = ARRAY_REGEX.match(line)
|
elsif match = ARRAY_REGEX.match(line)
|
||||||
_, val = match.captures
|
_, 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] = [] unless last_hash[last_empty_key].is_a?(Array)
|
||||||
|
|
||||||
last_hash[last_empty_key].push(val)
|
last_hash[last_empty_key].push(val)
|
||||||
@ -81,6 +84,14 @@ module Bundler
|
|||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def strip_comment(val)
|
||||||
|
if val.include?("#") && !val.start_with?("#")
|
||||||
|
val.split("#", 2).first.strip
|
||||||
|
else
|
||||||
|
val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# for settings' keys
|
# for settings' keys
|
||||||
def convert_to_backward_compatible_key!(key)
|
def convert_to_backward_compatible_key!(key)
|
||||||
key << "/" if /https?:/i.match?(key) && !%r{/\Z}.match?(key)
|
key << "/" if /https?:/i.match?(key) && !%r{/\Z}.match?(key)
|
||||||
|
@ -56,9 +56,10 @@ module Gem
|
|||||||
last_hash = nil
|
last_hash = nil
|
||||||
last_empty_key = nil
|
last_empty_key = nil
|
||||||
str.split(/\r?\n/) do |line|
|
str.split(/\r?\n/) do |line|
|
||||||
line = line.split("#", 2).first.strip if line.include?("#")
|
|
||||||
if match = HASH_REGEX.match(line)
|
if match = HASH_REGEX.match(line)
|
||||||
indent, key, quote, val = match.captures
|
indent, key, quote, val = match.captures
|
||||||
|
val = strip_comment(val)
|
||||||
|
|
||||||
convert_to_backward_compatible_key!(key)
|
convert_to_backward_compatible_key!(key)
|
||||||
depth = indent.size / 2
|
depth = indent.size / 2
|
||||||
if quote.empty? && val.empty?
|
if quote.empty? && val.empty?
|
||||||
@ -73,6 +74,8 @@ module Gem
|
|||||||
end
|
end
|
||||||
elsif match = ARRAY_REGEX.match(line)
|
elsif match = ARRAY_REGEX.match(line)
|
||||||
_, val = match.captures
|
_, 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] = [] unless last_hash[last_empty_key].is_a?(Array)
|
||||||
|
|
||||||
last_hash[last_empty_key].push(val)
|
last_hash[last_empty_key].push(val)
|
||||||
@ -81,6 +84,14 @@ module Gem
|
|||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def strip_comment(val)
|
||||||
|
if val.include?("#") && !val.start_with?("#")
|
||||||
|
val.split("#", 2).first.strip
|
||||||
|
else
|
||||||
|
val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# for settings' keys
|
# for settings' keys
|
||||||
def convert_to_backward_compatible_key!(key)
|
def convert_to_backward_compatible_key!(key)
|
||||||
key << "/" if /https?:/i.match?(key) && !%r{/\Z}.match?(key)
|
key << "/" if /https?:/i.match?(key) && !%r{/\Z}.match?(key)
|
||||||
|
@ -179,12 +179,12 @@ RSpec.describe Bundler::YAMLSerializer do
|
|||||||
yaml = <<~YAML
|
yaml = <<~YAML
|
||||||
---
|
---
|
||||||
foo: "bar"
|
foo: "bar"
|
||||||
buzz: # "foo"
|
buzz: "foo" # "bar"
|
||||||
YAML
|
YAML
|
||||||
|
|
||||||
hash = {
|
hash = {
|
||||||
"foo" => "bar",
|
"foo" => "bar",
|
||||||
"buzz" => {},
|
"buzz" => "foo",
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(serializer.load(yaml)).to eq(hash)
|
expect(serializer.load(yaml)).to eq(hash)
|
||||||
|
@ -439,7 +439,7 @@ E
|
|||||||
it "does not make bundler crash and ignores the configuration" do
|
it "does not make bundler crash and ignores the configuration" do
|
||||||
bundle "config list --parseable"
|
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
|
expect(err).to be_empty
|
||||||
|
|
||||||
ruby(<<~RUBY)
|
ruby(<<~RUBY)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user