Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments cannot be extracted from Flow-style YAML #608

Open
shuheiktgw opened this issue Jan 1, 2025 · 0 comments
Open

Comments cannot be extracted from Flow-style YAML #608

shuheiktgw opened this issue Jan 1, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@shuheiktgw
Copy link
Collaborator

Describe the bug
Comments do not seem to be extracted from Flow-style YAMLs using yaml.CommentToMap.

To Reproduce

From the example below, only "# comment2" can be extracted using yaml.CommentToMap, while all other comments appear to be ignored.

func TestComment(t *testing.T) {
	var input = []byte(`
key1: [] # comment1
key2: [ # comment2
 elm1, # comment3
 elm2, # comment4
] # comment5
key3: {} # comment6
key4: { # comment7
 key1: value1, # comment8
 key2: value2, # comment9
} # comment10
`)

	var f map[string]interface{}
	cm := yaml.CommentMap{}
	var err error
	if err = yaml.UnmarshalWithOptions(input, &f, yaml.CommentToMap(cm)); err != nil {
		panic(err)
	}

	for k, comments := range cm {
		fmt.Println("key: " + k)
		for _, comment := range comments {
			fmt.Println(comment.Texts)
		}
	}
} 

Version Variables

  • Go version: 1.23
  • go-yaml's Version: v1.15.13

Additional context
#419 seems to be related to this issue.

@shuheiktgw shuheiktgw added the bug Something isn't working label Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant