Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comma is inserted after comment when serializing flow map #528

Closed
WhiteAbeLincoln opened this issue Mar 4, 2024 · 0 comments
Closed

Comma is inserted after comment when serializing flow map #528

WhiteAbeLincoln opened this issue Mar 4, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@WhiteAbeLincoln
Copy link

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.

@WhiteAbeLincoln WhiteAbeLincoln added the bug Something isn't working label Mar 4, 2024
@eemeli eemeli closed this as completed in 750adbe Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant