aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2024-01-23 20:19:02 +0900
committergit <svn-admin@ruby-lang.org>2024-01-24 09:11:53 +0000
commit723deec9cf84342332896e48f50b4bf519492652 (patch)
treece1f8ce03382eeae125c80c394e567698820ec2b
parent1018dca09a55e7b21d701cfee0171b44ba26fe4a (diff)
downloadruby-723deec9cf84342332896e48f50b4bf519492652.tar.gz
[rubygems/rubygems] Keep compatibility of past versions
https://github.com/rubygems/rubygems/commit/54b67fb251
-rw-r--r--lib/bundler/yaml_serializer.rb13
-rw-r--r--lib/rubygems/yaml_serializer.rb13
-rw-r--r--spec/bundler/bundler/yaml_serializer_spec.rb4
-rw-r--r--spec/bundler/commands/config_spec.rb2
4 files changed, 27 insertions, 5 deletions
diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb
index abc931dc67..42e6aaf89d 100644
--- a/lib/bundler/yaml_serializer.rb
+++ b/lib/bundler/yaml_serializer.rb
@@ -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)
diff --git a/lib/rubygems/yaml_serializer.rb b/lib/rubygems/yaml_serializer.rb
index 7555c83d6b..128becc1ce 100644
--- a/lib/rubygems/yaml_serializer.rb
+++ b/lib/rubygems/yaml_serializer.rb
@@ -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)
diff --git a/spec/bundler/bundler/yaml_serializer_spec.rb b/spec/bundler/bundler/yaml_serializer_spec.rb
index 0b2c8e167c..316eaf1ca7 100644
--- a/spec/bundler/bundler/yaml_serializer_spec.rb
+++ b/spec/bundler/bundler/yaml_serializer_spec.rb
@@ -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)
diff --git a/spec/bundler/commands/config_spec.rb b/spec/bundler/commands/config_spec.rb
index c849384ff2..547fd2d869 100644
--- a/spec/bundler/commands/config_spec.rb
+++ b/spec/bundler/commands/config_spec.rb
@@ -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)