From 52737154289a7dba1f7e92b5439d888e5cb05617 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 7 Dec 2024 16:20:45 +1100 Subject: [PATCH] Fixed panic error #2211 --- pkg/yqlib/operator_traverse_path.go | 2 +- pkg/yqlib/operator_traverse_path_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/yqlib/operator_traverse_path.go b/pkg/yqlib/operator_traverse_path.go index aef22ce7..4f46b983 100644 --- a/pkg/yqlib/operator_traverse_path.go +++ b/pkg/yqlib/operator_traverse_path.go @@ -264,7 +264,7 @@ func doTraverseMap(newMatches *orderedmap.OrderedMap, node *CandidateNode, wante // if we don't find a match directly on this node first. var contents = node.Content - for index := 0; index < len(contents); index = index + 2 { + for index := 0; index+1 < len(contents); index = index + 2 { key := contents[index] value := contents[index+1] diff --git a/pkg/yqlib/operator_traverse_path_test.go b/pkg/yqlib/operator_traverse_path_test.go index 2bc78947..4a2c7917 100644 --- a/pkg/yqlib/operator_traverse_path_test.go +++ b/pkg/yqlib/operator_traverse_path_test.go @@ -35,6 +35,15 @@ steps: ` var traversePathOperatorScenarios = []expressionScenario{ + { + skipDoc: true, + description: "strange map with key but no value", + document: "!!null\n-", + expression: ".x", + expected: []string{ + "D0, P[x], (!!null)::null\n", + }, + }, { skipDoc: true, description: "access merge anchors",