Skip to content

Commit 98988fe

Browse files
authored
fix comment map with no body (#682)
1 parent 50b37c1 commit 98988fe

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

decode.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,10 +1860,10 @@ func (d *Decoder) parse(ctx context.Context, bytes []byte) (*ast.File, error) {
18601860
}
18611861
if v != nil {
18621862
normalizedFile.Docs = append(normalizedFile.Docs, doc)
1863+
cm := CommentMap{}
1864+
maps.Copy(cm, d.toCommentMap)
1865+
d.commentMaps = append(d.commentMaps, cm)
18631866
}
1864-
cm := CommentMap{}
1865-
maps.Copy(cm, d.toCommentMap)
1866-
d.commentMaps = append(d.commentMaps, cm)
18671867
for k := range d.toCommentMap {
18681868
delete(d.toCommentMap, k)
18691869
}

yaml_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ key: value # line comment
3636

3737
func TestStreamDecodingWithComment(t *testing.T) {
3838
yml := `
39+
# comment
40+
---
3941
a:
4042
b:
4143
c: # comment

0 commit comments

Comments
 (0)