fix: don't add trailing newline for empty values with spaceBefore#683
Closed
harihara-ai wants to merge 1 commit into
Closed
fix: don't add trailing newline for empty values with spaceBefore#683harihara-ai wants to merge 1 commit into
harihara-ai wants to merge 1 commit into
Conversation
When a YAML pair has an empty value followed by blank lines, the parser stores those blank lines in the pair's sep tokens. This causes value.spaceBefore = true on the null value, which makes stringifyPair add a trailing newline to the pair string. That trailing newline then combines with the blank line added at the parent collection level via key.spaceBefore, producing a double blank line. Fix: when ws === '\n' (from value.spaceBefore only, no comment) and valueStr === '' (empty value), set ws = ''. The blank line separation is already handled by the parent collection's key.spaceBefore. Fixes eemeli#639
Owner
|
Closing due to undeclared LLM use. |
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 #639.
Root cause
When a YAML pair has an empty value followed by blank lines (e.g.
b:ina:\n b:\n\nc:), the parser stores those blank lines in the pair'sseptokens. When the nested block-map exits before a new item starts at the same level, the special "move blank lines to next item's start" handling in the parser never fires. As a result,resolvePropsprocesses the blank lines insepand setsspaceBefore: trueon the empty value node.In
stringifyPair, this causesws = '\n'(fromvsb = !!value.spaceBefore), which adds a trailing newline to the pair string ('b:\n'). That trailing newline then combines with the blank line added at the parent collection level viapair.key.spaceBeforefor the following pair, producing a double blank line.Fix
One line in
stringifyPair.ts: whenws === '\n'(set fromvalue.spaceBeforewith nocommentBefore) andvalueStr === ''(empty value), setws = ''. The blank line separation between entries is already handled by the parent collection'spair.key.spaceBeforelogic — the trailing newline fromvsbis redundant and incorrect for empty values.Tests
Three test cases added inside the existing
No extra whitespace for empty valuesdescribe block intests/doc/stringify.ts, matching the minimal examples from the issue: