Description
stringify() of a multiline string whose first content line starts with a space produces a block scalar whose declared indentation indicator does not match the body indentation. The result either silently drops a leading space on every line, or is not parseable by the library's own parse().
At the document root ctx.indent is '', but the block indentation indicator is emitted as 1. The body lines, however, are indented with ctx.indent (empty at root), so the declared indicator and the actual body indentation disagree.
Reproduction
import { parse, stringify } from 'yaml'
stringify(' a\n b')
// => "|1-\n a\n b\n"
parse(stringify(' a\n b'))
// => " a\n b" ❌ a leading space was lost (expected " a\n b")
stringify(' indented\nlines')
// => "|1-\n indented\nlines\n"
parse(stringify(' indented\nlines'))
// ❌ throws YAMLParseError: Unexpected scalar at node end
More cases that currently fail to round-trip:
parse(stringify(' a\nb')) // throws
parse(stringify(' x\n y\nz')) // throws
parse(stringify(' deep\nshallow')) // throws
Expected
parse(stringify(x)) should equal x for any string x. Each of the cases above should round-trip exactly.
Environment
yaml 2.9.0 and current main (3.0.0 prerelease)
- Node.js 22
Description
stringify()of a multiline string whose first content line starts with a space produces a block scalar whose declared indentation indicator does not match the body indentation. The result either silently drops a leading space on every line, or is not parseable by the library's ownparse().At the document root
ctx.indentis'', but the block indentation indicator is emitted as1. The body lines, however, are indented withctx.indent(empty at root), so the declared indicator and the actual body indentation disagree.Reproduction
More cases that currently fail to round-trip:
Expected
parse(stringify(x))should equalxfor any stringx. Each of the cases above should round-trip exactly.Environment
yaml2.9.0and currentmain(3.0.0prerelease)