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",