-
Notifications
You must be signed in to change notification settings - Fork 151
Comma is inserted after comment when serializing flow map #528
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When serializing a flow mapping, the separating comma is appended to a trailing comment instead of after a value.
This results in an invalid yaml document (despite no changes being made to the document) because of a missing comma between flow map items.
This behavior does not occur with a flow sequence, just a flow map.
To Reproduce
const yaml = require('yaml')
const assert = require('node:assert')
const textBefore =
`test: {
items: {
first: { value: true }, # comment
second: { value: true }
},
array: [
first, # comment
second
]
}`
const textAfter =
`test:
{
items:
{
first: { value: true } # comment,
second: { value: true }
},
array:
[
first, # comment
second
]
}`
const doc = yaml.parseDocument(textBefore)
const docText = doc.toString()
// no error
assert.equal(docText.trim(), textAfter)
const docAfter = yaml.parseDocument(docText)
// throws error since expected is an array of one error:
/*
YAMLParseError: Missing , between flow map items at line 6, column 9:
first: { value: true } # comment,
second: { value: true }
^
*/
assert.deepStrictEqual( docAfter.errors, [])Expected behaviour
Comma should be in the correct position so that the document still parses after being stringified
Versions (please complete the following information):
- Environment: Node 20.11.1, Firefox 123.0, Edge 122.0.2365.66
yaml: 2.4.0
Additional context
Add any other context about the problem here.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working