Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Unexpected behavior around folded block scalars #827

@dangermike

Description

@dangermike

I'm seeing doubling of the first newline when using the folding style of block. I can replicate this using yaml.Node{...}, but it seems clearer to parse a string directly. This is my test harness:

package main

import (
	"os"

	yaml "gopkg.in/yaml.v3"
)

func main() {
	src := []byte(`
>
  line 1
  line 2
  line 3
    line 4
`)

	var data yaml.Node
	if err := yaml.Unmarshal(src, &data); err != nil {
		panic(err)
	}

	enc := yaml.NewEncoder(os.Stdout)
	if err := enc.Encode(&data); err != nil {
		panic(err)
	}
	enc.Close()
}```

The result is:

```text
>
    line 1 line 2 line 3

      line 4
      

The second newline between 3 & 4 is, I think a mistake. It becomes clearer if we indent line 2 like so (test):

	src := []byte(`
>
  line 1
    line 2
    line 3
      line 4
`)

This results in:

>
    line 1

      line 2
      line 3
        line 4

This is definitely incorrect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions