From 6f94991c2ab9a1022073afc6e4978096ee89e860 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Mon, 6 Apr 2026 18:41:54 +1000 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/yqlib/operator_system.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/pkg/yqlib/operator_system.go b/pkg/yqlib/operator_system.go index ba777f28..5f22508d 100644 --- a/pkg/yqlib/operator_system.go +++ b/pkg/yqlib/operator_system.go @@ -9,17 +9,38 @@ import ( ) func resolveSystemArgs(argsNode *CandidateNode) []string { + if argsNode == nil { + return nil + } + if argsNode.Kind == SequenceNode { args := make([]string, 0, len(argsNode.Content)) for _, child := range argsNode.Content { + // Only non-null scalar children are valid arguments. + if child == nil { + continue + } + if child.Kind != ScalarNode || child.Tag == "!!null" { + log.Warningf("system operator: argument must be a non-null scalar; got kind=%v tag=%v - ignoring", child.Kind, child.Tag) + continue + } args = append(args, child.Value) } + if len(args) == 0 { + return nil + } return args } - if argsNode.Tag != "!!null" { - return []string{argsNode.Value} + + // Single-argument case: only accept a non-null scalar node. + if argsNode.Tag == "!!null" { + return nil } - return nil + if argsNode.Kind != ScalarNode { + log.Warningf("system operator: args must be a non-null scalar or sequence of non-null scalars; got kind=%v tag=%v - ignoring", argsNode.Kind, argsNode.Tag) + return nil + } + return []string{argsNode.Value} } func resolveCommandNode(commandNodes Context) (string, error) {