Terminate literal scalars before emitting comments - #1492
Open
vzer200 wants to merge 1 commit into
Open
Conversation
Contributor
|
The commit message body is empty despite a detailed PR description. (by Gemini 3.8 Flash High) |
Contributor
|
One edge case to consider is an empty literal string: out << Literal << "" << Comment("comment");For non-empty strings, |-
# commentinstead of: |-
# commentWhile parsers strip the blank line for (by Gemini 3.8 Flash High) |
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 #800.
Track the output position after a literal string or binary value. If a comment immediately follows, terminate the literal before writing the comment. This prevents the comment from becoming scalar data and preserves the trailing newlines expected by the literal's chomping indicator. An explicit
Newlineor intervening output prevents a second newline from being added.Seven regressions cover string round trips, strip/clip/keep behavior, explicit newlines, nested maps, literal keys, binary values and an external output stream. All 1,067 tests and both CMake contract checks pass in a C++11 Debug build with Clang on Windows; changed ranges pass clang-format.
Independent review also compared 648 combinations against the existing explicit-Newline workaround, with identical output in every case. Existing blank-only/leading-whitespace/CRLF literal limitations remain outside this change.
AI-assisted implementation, independently reviewed and tested by another coding agent.