From f7d95021c140fc8804d662490aa6666affa8196b Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Tue, 12 Jan 2021 09:30:24 +1100 Subject: [PATCH] Fixed has operator for top level node --- pkg/yqlib/operator_has.go | 5 +++-- pkg/yqlib/operator_has_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/yqlib/operator_has.go b/pkg/yqlib/operator_has.go index 1737251..73e8501 100644 --- a/pkg/yqlib/operator_has.go +++ b/pkg/yqlib/operator_has.go @@ -24,8 +24,9 @@ func hasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathT candidate := el.Value.(*CandidateNode) // grab the first value - var contents = candidate.Node.Content - switch candidate.Node.Kind { + candidateNode := UnwrapDoc(candidate.Node) + var contents = candidateNode.Content + switch candidateNode.Kind { case yaml.MappingNode: candidateHasKey := false for index := 0; index < len(contents) && !candidateHasKey; index = index + 2 { diff --git a/pkg/yqlib/operator_has_test.go b/pkg/yqlib/operator_has_test.go index dc0c3d2..1ca54f5 100644 --- a/pkg/yqlib/operator_has_test.go +++ b/pkg/yqlib/operator_has_test.go @@ -5,6 +5,14 @@ import ( ) var hasOperatorScenarios = []expressionScenario{ + { + skipDoc: true, + document: `a: hello`, + expression: `has("a")`, + expected: []string{ + "D0, P[], (!!bool)::true\n", + }, + }, { description: "Has map key", document: `- a: "yes"