diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2024-01-23 19:14:39 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-01-24 09:11:53 +0000 |
| commit | 1018dca09a55e7b21d701cfee0171b44ba26fe4a (patch) | |
| tree | bab2e9accdfa90133ee828ee9e389d36ac0b2a47 | |
| parent | 53d0cf442a1dfc1616a3870a65d5c867e0fec2dd (diff) | |
[rubygems/rubygems] Skip to load commented out words
https://github.com/rubygems/rubygems/commit/e6a9148ba2
| -rw-r--r-- | lib/bundler/yaml_serializer.rb | 1 | ||||
| -rw-r--r-- | lib/rubygems/yaml_serializer.rb | 1 | ||||
| -rw-r--r-- | spec/bundler/bundler/yaml_serializer_spec.rb | 15 | ||||
| -rw-r--r-- | spec/bundler/commands/config_spec.rb | 2 |
4 files changed, 18 insertions, 1 deletions
diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index 37ccc46c26..abc931dc67 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -56,6 +56,7 @@ 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 convert_to_backward_compatible_key!(key) diff --git a/lib/rubygems/yaml_serializer.rb b/lib/rubygems/yaml_serializer.rb index 947fda0911..7555c83d6b 100644 --- a/lib/rubygems/yaml_serializer.rb +++ b/lib/rubygems/yaml_serializer.rb @@ -56,6 +56,7 @@ 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 convert_to_backward_compatible_key!(key) diff --git a/spec/bundler/bundler/yaml_serializer_spec.rb b/spec/bundler/bundler/yaml_serializer_spec.rb index 913b0235b8..0b2c8e167c 100644 --- a/spec/bundler/bundler/yaml_serializer_spec.rb +++ b/spec/bundler/bundler/yaml_serializer_spec.rb @@ -174,6 +174,21 @@ RSpec.describe Bundler::YAMLSerializer do expect(serializer.load(yaml)).to eq(hash) end + + it "skip commented out words" do + yaml = <<~YAML + --- + foo: "bar" + buzz: # "foo" + YAML + + hash = { + "foo" => "bar", + "buzz" => {}, + } + + expect(serializer.load(yaml)).to eq(hash) + end end describe "against yaml lib" do diff --git a/spec/bundler/commands/config_spec.rb b/spec/bundler/commands/config_spec.rb index 547fd2d869..c849384ff2 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 eq("#mirror.https://rails-assets.org/=http://localhost:9292") + expect(out).to be_empty expect(err).to be_empty ruby(<<~RUBY) |
