Repository navigation
Conversation
A block mapping key is written on its mapping's line, so `scalarLayout()` saw it one level deeper than it really is and never applied the c-forbidden guard. At the document root the key starts at column 0, so a key beginning with `--- ` or `... ` was dumped unquoted: reloading either failed (`--- x: 1`) or silently changed the key (`... x: 1` -> `x`). Report the mapping's indentation as the key's first-line shift, and add a regression test for root, nested and sequence-item keys, nodeca#805.
This branch has not been deployed
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.
Summary
dump()wrote a root-level block mapping key that starts with---or...as a plain scalar at column 0, where those prefixes are documentboundary markers. The result either fails to reload or reloads with the key
silently changed:
Cause
scalarLayout()derivesshiftOfFirstLinefrom the scalar'slevel.writeBlockMapping()passeslevel + 1for a key, because the key scalar isone level deeper in the AST, but writes the key on the mapping's own line. At
the document root the key really starts at column 0 while the layout reports
indent * 1 = 2, andcanUsePlain()only applies the c-forbidden guard whenshiftOfFirstLine === 0. The guard therefore never fired for keys.For a block-context key, report the mapping's indentation
(
indent * (level - 1)) as the first-line shift. Flow keys keep the oldvalue: they always follow
{or,and cannot start a line.Result
Only content that is actually written at column 0 is quoted, so nested and
sequence-item keys stay plain. The diff-summary example from the report
(
--- a/src/gateway/server.ts,... 2 files omitted) now round-trips too.Tests
Added
quotes a root block mapping key that would read as a document markerto
test/core/units/dump-scalar-styles.test.mjs; it asserts the dumped textand the reloaded value for
--- x,... x,---,...,indent: 4, andthat nested and sequence-item keys stay plain. The new test fails on the
current master and passes with the change.
npm test(lint, build,tsc --noEmit, yaml-test-suite, core tests):1647 tests, 1634 pass, 0 fail, 13 skipped.
Fixes #805.