Skip to content

Incorrect indentation for block sequence with newlines #626

Open
@shuheiktgw

Description

Describe the bug
When marshaling a block sequence that contains a newline, the output does not appear to respect the yaml.Indent option.

To Reproduce

package main

import (
	"fmt"

	"github.com/goccy/go-yaml"
)

func main() {
	input := map[string][]string{
		"key1": {"value1\nvalue2"},
	}

	got, err := yaml.MarshalWithOptions(input, yaml.Indent(4))
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(got))
}

This outputs:

key1:
- |-
  value1
  value2

But it should have been:

key1:
- |-
    value1
    value2

Version Variables

  • Go version: 1.23
  • go-yaml's Version: 1.15.15

Additional context
This is a follow up issue for #625.

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