Fix off-by-one excluding U+10FFFF from valid Unicode range in emitter#918
Open
Fix off-by-one excluding U+10FFFF from valid Unicode range in emitter#918
Conversation
The supplementary plane range check in analyze_scalar uses strict less-than (< U+10FFFF) instead of less-than-or-equal (<= U+10FFFF). This excludes U+10FFFF, a valid Unicode code point per the YAML spec's c-printable production, causing it to be treated as a special character and unnecessarily forcing double-quoted style. The reader module correctly includes U+10FFFF in its acceptance range.
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.
Summary
The emitter's
analyze_scalarmethod has an off-by-one error that excludes U+10FFFF from the valid Unicode range, causing it to be treated as a "special character" and forcing double-quoted scalar style.Problem
The supplementary plane check uses strict less-than:
This excludes U+10FFFF, which is a valid Unicode code point per the YAML spec's
c-printableproduction (YAML 1.1 section 4.1):Meanwhile,
reader.pycorrectly uses an inclusive upper bound in its character validation regex:'\U00010000-\U0010ffff'This creates an inconsistency: the reader accepts U+10FFFF, but the emitter treats it as special, unnecessarily forcing double-quoted style when the scalar could use plain, single-quoted, or block styles.
Demonstration
Fix
Change
<to<=to include U+10FFFF in the valid range, matching both the YAML spec and the reader's validation.