Repository navigation
fix: preserve multiline scalar content and formatting idempotence - #332
Open
TyceHerrman wants to merge 2 commits into
Open
TyceHerrman wants to merge 2 commits into
TyceHerrman wants to merge 2 commits into
Conversation
Protect multiline scalar content using scanner-derived ranges and preserve block style for trailing whitespace. Track the end of content separately from trailing breaks discarded by block chomping, retaining structural blank separators without changing scalar values. Use the existing unlimited line scanner in both passes. Derived from Michael Tingley's yamlfmt fork at 3e76013, including 5a4c612, 70c137d and 3e76013. Exclude additive indentation and the output-scan shortcut. Add regressions for literal sentinel text, scalar separators, LF/CRLF, both retention modes, and lines beyond 10 MiB. The tests expose both regressions on the previous PR head. Full Go tests pass at this commit on Go 1.25.1. Related: google#86 and google#280. AI assistance: Codex extracted, adjusted and validated this patch in cloud Linux.
Start folded-scalar look-ahead at the current byte offset and bound-check it. Take the core correction from ultimateanu's google#322 without its unrelated cleanup. Add decoded-value and idempotence regression coverage across retention modes, folded scanning settings and width limits. Extend separator tests to folded keep-chomping styles, which depend on this correction. The combined patch passes 396 independent YAML 1.2 preservation cases, 384 nh file/configuration cases, full tests, vet, CLI integration and license checks on Go 1.25.1. The closest nh configuration changes only one document marker. Source: google#322 Related: google#86 and google#313. AI assistance: Codex integrated and validated the patch in cloud Linux.
TyceHerrman
force-pushed
the
fix/scalar-content-preservation
branch
from
October 20, 2026 02:04
81f75e1 to
7228b20
Compare
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.
Retaining blank lines can insert
#magic___^_^___lineinto multiline scalar values, and trailing whitespace can force block scalars into quoted output. Folded scalars with more-indented lines can also gain newlines on successive formatting passes.This change protects scalar content using scanner-derived ranges, preserves structural blank separators and unlimited line scanning, retains block style with trailing whitespace, and corrects folded-scalar look-ahead.
Fixes #86.
Fixes #313.
Related: #280 (already closed).
Commit organization and provenance
This PR overlaps #322 and does not claim its correction as new work. Both sources are credited in the commit messages. Google's CLA check passes for the submitted commits; the original sources' contributors' CLA status has not been independently verified.
Validation
The revised tree passes on cloud Linux with Go 1.25.1:
make test,make vet,make integrationtest, andmake addlicense_check.The first commit passes the full Go test suite independently. Earlier Go 1.24.8/1.27.1 results apply to the previous revision; this revised tree was tested with Go 1.25.1. External matrices are broader than the committed focused tests. Intentional trailing whitespace in fixtures exercises the bug.
Existing limitations outside this change remain: marker-prefix comments can collide with the placeholder, empty YAML documents can be lost, and
%YAML 1.2directives are rejected. These inputs do not occur in the tested nh corpus. Windows, macOS, and Nix integration were not tested.AI disclosure: Codex extracted, adjusted, validated these changes and prepared this PR in an isolated cloud environment. Results come from that execution, not an independent manual reproduction.