dart-lang / yaml_edit

A library for YAML manipulation with comment and whitespace preservation.
https://pub.dev/packages/yaml_edit
BSD 3-Clause "New" or "Revised" License
27 stars 16 forks source link

Fix errors caused by newline and whitespace in folded string #43

Closed setcy closed 1 year ago

setcy commented 1 year ago

fixes: #41

Test data:

input: hello \n world output:

>-
  hello 
   world

input: hello \n\n world output:

>-
  hello 

   world

input: hello \n \n world output:

>-
  hello 

   world

input: hello \nstring\n world output:

>-
  hello 

  string
   world
setcy commented 1 year ago

Hi @jonasfj, thanks for the review!

I have pushed a new commit that updates the comment and improves the code by using .split('\n').

Maybe this is a separate issue, but might also be worth considering if we should address it here.

Are there strings that cannot be written as folded string?

Playing around I had a hard time writing T or \n T

For these conditions, we can use block styles with indication indicators to implement it.

condition 1:

input: hello output:

>-3
   hello

condition 2:

input: \n hello output:

>-3

   hello

condition 3:

input: \n \n hello \n output:

>-3

    hello 

note: Some yaml conversion tools could not correctly parse condition 3, they parsed the output as \n\n hello