We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug
The ast.DocumentNode panics on empty document, example program:
ast.DocumentNode
https://go.dev/play/p/YmrzDKhtFNp
package main import ( "fmt" "github.com/goccy/go-yaml/lexer" "github.com/goccy/go-yaml/parser" ) func main() { f, err := parser.Parse(lexer.Tokenize(""), 0) if err != nil { panic(err) } fmt.Println(f.String()) }
The above program fails with panic:
panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x4ada54] goroutine 1 [running]: github.com/goccy/go-yaml/ast.(*DocumentNode).String(0xc0000162a0) /tmp/gopath1302303734/pkg/mod/github.com/goccy/go-yaml@v1.15.5/ast/ast.go:578 +0xb4 github.com/goccy/go-yaml/ast.(*File).String(0x0?) /tmp/gopath1302303734/pkg/mod/github.com/goccy/go-yaml@v1.15.5/ast/ast.go:535 +0x78 main.main() /tmp/sandbox432899830/prog.go:15 +0x34
This seems to be an regression introduced in v1.15.0 as the above same program works in v1.14.3 :
https://go.dev/play/p/VubIuMgDfYQ
I believe this is because now the body of the document node can be nil due to the new implementation in here:
go-yaml/parser/parser.go
Lines 107 to 109 in 3399084
while the DocumentNode.String method skips the nil check on body:
DocumentNode.String
go-yaml/ast/ast.go
Line 578 in 3399084
To Reproduce
Please provide a minimum yaml content that can be reproduced. We are more than happy to use Go Playground
Expected behavior
.String() should not panic for an empty document node
.String()
Screenshots If applicable, add screenshots to help explain your problem.
Version Variables
Additional context Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
fix: empty document should not panic on String()
b1de640
fixes goccy#629
6f80c57
Successfully merging a pull request may close this issue.
Describe the bug
The
ast.DocumentNode
panics on empty document, example program:https://go.dev/play/p/YmrzDKhtFNp
The above program fails with panic:
This seems to be an regression introduced in v1.15.0 as the above same program works in v1.14.3 :
https://go.dev/play/p/VubIuMgDfYQ
I believe this is because now the body of the document node can be nil due to the new implementation in here:
go-yaml/parser/parser.go
Lines 107 to 109 in 3399084
while the
DocumentNode.String
method skips the nil check on body:go-yaml/ast/ast.go
Line 578 in 3399084
To Reproduce
Please provide a minimum yaml content that can be reproduced.
We are more than happy to use Go Playground
Expected behavior
.String()
should not panic for an empty document nodeScreenshots
If applicable, add screenshots to help explain your problem.
Version Variables
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: