yamlloader: Properly handle colons in inline dicts #47104
Merged
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.
PyYAML's scanner is not written to handle Python's unicode literal strings, since they are not part of the YAML spec. With all strings loaded in the YAML context now being unicode types, this causes errors when scanning the document to construct the next node. The unicode string literal is misidentified as a plain scalar and any colons within it are interpreted as delimiting a mapping node. Since no whitespace appears after the colon, this causes scanning error.
To fix it, we check for this scanning error and reset the scanner's position and check if the first char is the "u" prefix. If so, and if the following char is a quote, then we attempt to scan for a string literal instead.
Resolves #46929.