fix: Round-trip block scalars with leading space on first line#693
Open
Noethix55555 wants to merge 1 commit into
Open
fix: Round-trip block scalars with leading space on first line#693Noethix55555 wants to merge 1 commit into
Noethix55555 wants to merge 1 commit into
Conversation
…i#692) At the document root the indentation indicator was emitted as 1 while the body lines were indented with the empty root indent, so stringify() output either dropped a leading space per line or was unparseable by parse(). Indent the body to match the declared indicator, and account for the added indent when deciding whether a folded first line is more-indented. The existing foldFlowLines eemeli#55 test asserted the buggy, unparseable output; its expectation is updated to the corrected, round-trippable output.
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 #692.
Problem
stringify()of a multiline string whose first content line starts with a space produced a block scalar whose declared indentation indicator did not match the body indentation. At the document rootctx.indentis'', but the indicator was emitted as1, while body lines were prefixed with the (empty) root indent. As a result the output either silently dropped a leading space per line or was not parseable byparse():Fix
In
blockString(src/stringify/stringifyString.ts) introduce abodyIndentthat honors the declared indicator at the root (a single space when the value starts with a space andindentis empty), and use it for the body in both the literal and folded paths. The folded path additionally accounts for this added indent when deciding whether the first line is "more-indented", so a more-indented first line is no longer incorrectly folded.Non-root and non-leading-space behavior is unchanged.
Tests
tests/doc/stringify.tscovering several leading-space cases. These fail onmainand pass with the fix.tests/doc/foldFlowLines.ts"More-indented first line (Long strings that start with spaces aren't rendered properly (and lose newlines) #55)" test: it was asserting the buggy output, whose expected string was itself unparseable. It now asserts the corrected, round-trippable output and additionally checks that the output parses back to the original.The full
vitest runsuite passes (the two external test-suite files require submodule data and fail identically on a pristine tree).LLM assistance
This pull request was prepared with the assistance of an LLM (declared per CONTRIBUTING.md). All changes were reviewed and verified locally.