summaryrefslogtreecommitdiff
path: root/lib/bundler/yaml_serializer.rb
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 /lib/bundler/yaml_serializer.rb
parent1018dca09a55e7b21d701cfee0171b44ba26fe4a (diff)
[rubygems/rubygems] Keep compatibility of past versions
https://github.com/rubygems/rubygems/commit/54b67fb251
Diffstat (limited to 'lib/bundler/yaml_serializer.rb')
-rw-r--r--lib/bundler/yaml_serializer.rb13
1 files changed, 12 insertions, 1 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)