Quote scalars with a leading or trailing tab - #1125
Open
gaoflow wants to merge 1 commit into
Open
Conversation
The emitter already forces quoting for a leading or trailing space, but the whitespace check in AnalyzeScalar used a space-only predicate, so a leading or trailing tab was emitted as a plain scalar. On read-back the tab is stripped as indentation, or (when it precedes a flow indicator) the parser rejects the emitter's own output with a SemanticErrorException (aaubry#732, aaubry#493). Use IsWhite() so a tab is treated like a space for leading/trailing detection. Interior tabs are unaffected and stay plain.
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.
AnalyzeScalaralready forces quoting for a scalar with a leading or trailing space, but the whitespace check it uses (buffer.IsSpace()) is space-only, so a leading or trailing tab falls through and the value is emitted as a plain scalar. That output is not self-consistent:SemanticErrorException.Repro on the default serializer:
This also covers the tab cases from #493 (e.g. a
Dictionaryvalue of"\thello").Note this is the default emitter path, separate from the
\sregex inTypeAssigningEventEmitterthat #732 was closed against - that fix only applies with.WithQuotingNecessaryStrings(), so the plain default builder above still reproduces.Fix: use the existing
IsWhite()(space or tab) predicate for the leading/trailing whitespace detection, so a tab is treated like a space. The change is limited to leading/trailing detection - an interior tab is safe unquoted and stays plain ("x\ty"still emits asx\tyand round-trips).Tests in
SerializationTestscover leading/trailing/only tab round-trips, the"\t,"list no-throw case, and pin that an interior tab stays plain and that leading/trailing spaces are unchanged. Full suite green on net10.0.