Skip to content

AST nested sequence left-trimmed when calling String #694

@joshjcarrier

Description

@joshjcarrier

Describe the bug

Given an nested sequence:

arr:
  - arr2: 
      [ "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" ]

Parse the yaml into an ast.File. Then print the output of ast.String().

arr:
  - arr2:
    e", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]

The nested sequence has been left-trimmed and is no longer syntactically an array.

To Reproduce

Go playground

package main

import (
	"fmt"

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

func main() {
	yml := `
arr:
  - arr2: 
      [ "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" ]
`

	ast, err := parser.ParseBytes([]byte(yml), parser.ParseComments)
	if err != nil {
		fmt.Println(err)
	}

	got := ast.String()
	fmt.Println(got)
}

Expected behavior

Expected valid and semantically identical YML to be emitted.

Version Variables

  • Go version: 1.24
  • go-yaml's Version: 1.17.1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions