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

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

Closed
remcohaszing opened this issue Jul 24, 2024 · 2 comments
Closed

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

remcohaszing opened this issue Jul 24, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@remcohaszing
Copy link

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

@eemeli
Copy link
Owner

eemeli commented Jul 24, 2024

Confirming, the serialization adds an extra initial newline for folded block scalars (>) when the lineWidth + indent is less than minContentWidth (by default 20).

@eemeli eemeli closed this as completed in 534d8ad Jul 24, 2024
@eemeli
Copy link
Owner

eemeli commented Jul 24, 2024

Fixed in 2.5.0.

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

2 participants