Repository navigation
Conversation
ResolveFlowScalar() and resolveBlockScalar() now check the raw source of each scalar for C0 control characters other than TAB, LF and CR, and call onError() with a new NON_PRINTABLE_CHAR error code for each such character. Previously such characters were silently included in the resolved value, even though the characters excluded from the c-printable production of the YAML spec should be verified as excluded. The other c-printable exclusions (DEL, C1 control characters, U+FFFE, U+FFFF) are deliberately not flagged, as JSON allows those characters as-is within strings, and this library aims to parse valid JSON as YAML. Fixes eemeli#703
Owner
|
Please review the contributing guidelines and try again. |
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.
Fixes #703.
This adds a
NON_PRINTABLE_CHARerror (a recoverableYAMLParseError) when the raw source of a scalar includes a C0 control character other than TAB, LF and CR, as those characters are excluded from the c-printable production of the YAML spec. As suggested in the issue, the check runs during composition inresolveFlowScalar()andresolveBlockScalar(), so every scalar style (plain, single-quoted, double-quoted, block literal and block folded) is covered, and each offending character is reported separately with its position.Values that include such characters via double-quoted escape sequences (e.g.
"a\x01b") keep parsing without errors, as those escapes are the spec-sanctioned way to represent control characters. Error recovery is unchanged: the scalar still resolves to its source text, and onlydoc.errorsgains an entry.The other
c-printableexclusions (DEL, C1 control characters, U+FFFE, U+FFFF) are deliberately not flagged, as JSON allows those characters as-is within strings and this library aims to parse valid JSON as YAML; flagging them would break e.g. they_string_unescaped_char_deleteandy_string_nonCharacterInUTF-8_U+FFFFcases in the JSON test suite. Happy to extend the check (and escape those characters in the stringifier) if fullc-printableenforcement is preferred.Verification:
npm test— 3398 tests passed, including 11 new cases intests/doc/errors.tsnpm run lintnpx prettier --check .npm run test:typesnpm run buildnpm run test:dist— 3398 tests passednpm run test:dist:types