Skip to content

fix(stringify): use indentStep length for mapping block scalar indent indicator - #738

Open
princejain756 wants to merge 1 commit into
eemeli:mainfrom
princejain756:fix/block-scalar-indent-indicator
Open

princejain756 wants to merge 1 commit into
eemeli:mainfrom
princejain756:fix/block-scalar-indent-indicator

Conversation

@princejain756

Copy link
Copy Markdown

Issue

fixes #733

LLM Use

An LLM coding assistant helped draft the fix, the tests, and this description. I reviewed the change, ran the test suite locally, and verified the output by hand for indent values 1, 2, and 4.

Description

blockString() hardcoded the indentation indicator '2' whenever a block scalar's first line started with a space and the serialization context had non-empty indent. For mapping (and set) values the content is actually indented by ctx.indentStep, so stringify() called with indent other than 2 wrote an indicator that disagreed with the emitted content and produced output that did not re-parse to the same document.

The fix resets implicitKey to undefined for block sequence items (whose scalar content always indents by 2 relative to the - marker) and uses ctx.indentStep.length when serializing inside a mapping or set, so the indicator matches the real content indent for any indent value.

Regression tests cover indent 1, 2, and 4 for mapping values, set values, and block sequence items.

… indicator

When a block scalar starts with a space and is serialized inside a mapping or set, its content is indented by `ctx.indentStep` relative to its parent node. Previously `blockString()` hardcoded `'2'` whenever `indent` was non-empty, causing `stringify()` with `indent` other than 2 to emit an indentation indicator that disagreed with the content indentation.

Reset `implicitKey` to `undefined` for block sequence items (which always indent by 2 spaces relative to `-`) and use `ctx.indentStep.length` when `ctx.implicitKey === false`.

Fixes eemeli#733

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stringify() writes wrong block scalar indentation indicator for mapping values with indent other than 2

1 participant