Skip to content

Comment that is indented farther causes a parsing error #713

@rcjsuen

Description

@rcjsuen

Describe the bug
Having a comment that is indented farther than the content around it causes a parsing error.

To Reproduce
You can reproduce the error with this link.

[4:5] value is not allowed in this context. map key-value is pre-defined
   2 | topLevelNode:
   3 |   attribute: true
>  4 |     # comment
           ^
topLevelNode:
  attribute: true
    # comment
package main

import (
	"fmt"

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

func main() {
	_, err := parser.ParseBytes([]byte(`
topLevelNode:
  attribute: true
    # comment
`), parser.ParseComments)
	fmt.Println(err)

}

Expected behavior
Since it is a comment I would have expected it to be able to handle comments even if it is indented in a strange way.

Screenshots
No screenshots needed as the code and playground link should be sufficient.

Version Variables

  • Go version: 1.24.1 darwin/arm64
  • go-yaml's Version: v1.17.1

Additional context
I do not think there is anything else to add. Let me know if you need anything else.

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