Skip to content

doc.toString generates incorrect whitespace if lineWidth < 22 #562

Closed
@remcohaszing

Description

@remcohaszing

Describe the bug
When serializing a blockquote with a line width of 21 or less, it is prefixed with additional whitespace.

To Reproduce
Run the following script:

import {parseDocument} from 'yaml'

let yaml = `comments: >
  test test test test test test`

for(let i = 0; i < 10; i++) {
  const doc = parseDocument(yaml)
  yaml = doc.toString({
    lineWidth: 22,
  })
  console.dir(yaml)
}


for(let i = 0; i < 10; i++) {
  const doc = parseDocument(yaml)
  yaml = doc.toString({
    lineWidth: 21,
  })
  console.dir(yaml)
}

Expected behaviour
When serializing a document, and then parsing again, the same document is produced. This holds true for the first loop using a lineWidth of 22, but not the second loop using a lineWidth of 21.

Versions (please complete the following information):

  • Environment: Node.js 22.5.1
  • yaml: 2.4.5

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions