From 54cd51fe01b441bedd504b4d6f9ce80f12be94dc Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Fri, 20 Dec 2024 20:10:01 +0900 Subject: [PATCH] add nil guard (#600) --- decode.go | 3 +++ path.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/decode.go b/decode.go index 82915cb..ec60fc6 100644 --- a/decode.go +++ b/decode.go @@ -211,6 +211,9 @@ func (d *Decoder) setToOrderedMapValue(node ast.Node, m *MapSlice) error { } func (d *Decoder) setPathToCommentMap(node ast.Node) { + if node == nil { + return + } if d.toCommentMap == nil { return } diff --git a/path.go b/path.go index aaa3477..2192086 100644 --- a/path.go +++ b/path.go @@ -271,6 +271,9 @@ func (p *Path) FilterFile(f *ast.File) (ast.Node, error) { // FilterNode filter from node by YAMLPath. func (p *Path) FilterNode(node ast.Node) (ast.Node, error) { + if node == nil { + return nil, nil + } n, err := p.node.filter(node) if err != nil { return nil, err