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

Fix panic when parsing unattached comment #565

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,9 @@ func (p *parser) parseDirective(ctx *context, g *TokenGroup) (*ast.DirectiveNode

func (p *parser) parseComment(ctx *context) (ast.Node, error) {
cm := p.parseHeadComment(ctx)
if ctx.isTokenNotFound() {
return cm, nil
}
node, err := p.parseToken(ctx, ctx.currentToken())
if err != nil {
return nil, err
Expand Down
8 changes: 8 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,14 @@ foo: | # comment
yaml: `
foo: > # comment
x: 42
`,
},
{
name: "unattached comment",
yaml: `
# This comment is in its own document
---
a: b
`,
},
}
Expand Down