Parsing a YAML document that contains a flow collection (like [key]: value) as a map key throws an IMPOSSIBLE error when the flow collection is preceded by a blank line or a comment line.
Parsing a YAML document that contains a flow collection (like [key]: value) as a map key throws an IMPOSSIBLE error when the flow collection is preceded by a blank line or a comment line.
YAML.parse('1: 2\n\n[3]: 4'), a flow collection key after a blank lineYAML.parse('1: 2\n# comment\n[3]: 4'), a flow collection key after a comment lineYAML.parse('?\n[3]: 4'), a flow collection key after an empty explicit keyThe YAML should parse successfully into a map with two entries: the first key 1 with value 2, and the second key [ 3 ] (a sequence) with value 4.
The parser throws a YAMLParseError with code IMPOSSIBLE:
YAMLParseError: Map comment with trailing content at line 3, column 1:
[3]: 4
^
at Composer.onError (...)
at Object.resolveBlockMap (...)
code: 'IMPOSSIBLE',
pos: [ ..., ... ],
linePos: [ { line: 3, col: 1 }, { line: 3, col: 2 } ]
This occurs when using flow collections as implicit block map keys, a valid YAML 1.2 construct. The issue appears after upgrading the yaml package. A workaround is to avoid blank lines or comments before flow collection keys, but this changes the formatting of valid YAML documents.
Adapted from eemeli/yaml (ISC).
Visible test command
TZ=UTC npx --no-install vitest run --coverage.enabled=falseThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
flow-collection-key-after-blank-line-or-comment
Changes under src/ are evaluated.