Fix a bug that Gem::YAMLSerializer.load ignores quotation#9552
Open
kou wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Gem::YAMLSerializer.load incorrectly treating quoted scalars containing : as mappings (notably within requirements entries in .gemspec YAML), so metadata in .gem files is deserialized correctly.
Changes:
- Add handling in the YAMLSerializer parser intended to recognize single/double-quoted scalars and parse them as scalars instead of mappings.
- Add a regression test ensuring quoted
requirementsentries load as an array of strings.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lib/rubygems/yaml_serializer.rb |
Adjusts node-type detection to treat quoted lines as scalars to avoid : triggering mapping parsing. |
test/rubygems/test_gem_safe_yaml.rb |
Adds a test case for quoted requirements values deserializing to strings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
96
to
102
| if stripped.start_with?("- ") || stripped == "-" | ||
| parse_sequence(indent, anchor) | ||
| elsif stripped.start_with?("\"") and stripped.end_with?("\"") | ||
| parse_plain_scalar(indent, anchor) | ||
| elsif stripped.start_with?("'") and stripped.end_with?("'") | ||
| parse_plain_scalar(indent, anchor) | ||
| elsif stripped =~ MAPPING_KEY_RE && !stripped.start_with?("!ruby/object:") |
Comment on lines
+98
to
+100
| elsif stripped.start_with?("\"") and stripped.end_with?("\"") | ||
| parse_plain_scalar(indent, anchor) | ||
| elsif stripped.start_with?("'") and stripped.end_with?("'") |
Comment on lines
+321
to
+333
| def test_requirement_quote | ||
| yaml = <<~YAML | ||
| requirements: | ||
| - "system: arrow-glib>=25.0.0: amazon_linux: arrow-glib-devel" | ||
| - 'system: arrow-glib>=25.0.0: fedora: libarrow-glib-devel' | ||
| YAML | ||
|
|
||
| assert_equal([ | ||
| "system: arrow-glib>=25.0.0: amazon_linux: arrow-glib-devel", | ||
| "system: arrow-glib>=25.0.0: fedora: libarrow-glib-devel", | ||
| ], | ||
| yaml_load(yaml)["requirements"]) | ||
| end |
`"a: b"` must be processed as a string value (`a: b`) not a map
value (`{"a" => "b"}`).
Member
|
Thanks, Should we cover This change introduce |
Member
Author
|
Oh, I didn't notice the case. We may need to restructure the current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #9551
What was the end-user or developer problem that led to this PR?
.gemspecis serialized to YAML (metadata.gz) in.gem.metadata.gzmay use double quote for string value like:Gem::YAMLSerializer.loadignores the quotation and parses it as a map:What is your fix for the problem, implemented in this PR?
Recognize quotation and parse quoted value as a string value.
Make sure the following tasks are checked