diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index 93d08a05aa..ab1eb6dbcf 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -41,7 +41,7 @@ module Bundler HASH_REGEX = / ^ ([ ]*) # indentations - (.+) # key + ([^#]+) # key excludes comment char '#' (?::(?=(?:\s|$))) # : (without the lookahead the #key includes this when : is present in value) [ ]? (['"]?) # optional opening quote diff --git a/lib/rubygems/yaml_serializer.rb b/lib/rubygems/yaml_serializer.rb index af86c63ef7..f89004f32a 100644 --- a/lib/rubygems/yaml_serializer.rb +++ b/lib/rubygems/yaml_serializer.rb @@ -41,7 +41,7 @@ module Gem HASH_REGEX = / ^ ([ ]*) # indentations - (.+) # key + ([^#]+) # key excludes comment char '#' (?::(?=(?:\s|$))) # : (without the lookahead the #key includes this when : is present in value) [ ]? (['"]?) # optional opening quote diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index b28dcf503e..4230eda4d3 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -569,10 +569,14 @@ if you believe they were disclosed to a third party. yaml = <<~YAML --- :foo: bar # buzz + #:notkey: bar YAML actual = Gem::ConfigFile.load_with_rubygems_config_hash(yaml) assert_equal("bar", actual[:foo]) + assert_equal(false, actual.key?("#:notkey")) + assert_equal(false, actual.key?(:notkey)) + assert_equal(1, actual.size) end def test_s3_source