eemeli / yaml

YAML parser and stringifier for JavaScript
https://eemeli.org/yaml
ISC License
1.31k stars 115 forks source link

`map` parsed as `string` #550

Closed RedCMD closed 5 months ago

RedCMD commented 6 months ago

Describe the bug a flow map with an empty value should be parsed as map, not string Flow nodes and flow keys are not allowed to contain the character set :]

To Reproduce

[a:b]
---
[c:]
---
[:]
---
a:b
---
c:
---
:

Expected behaviour [c:] should be a map with c key and empty for the value [a:b] is correctly parsed as a string [:] is correctly parsed as an empty map

Versions:

Additional context image

eemeli commented 5 months ago

[c:] should be a map with c key and empty for the value

Agreed, there's something wrong in the ns-plain-char lookahead, which should recognise the ] after the : as a c-flow-indicator, so that this parses the same as [c:,] or [c: ].

[:] is correctly parsed as an empty map

To be picky, it's a sequence with a map as a value, and that map has a single pair with empty key and value. But it is indeed correctly parsed.