Skip to content

Commit e10e812

Browse files
mikefarahCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 53abbba commit e10e812

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

cmd/root.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ yq -P -oy sample.json
212212

213213
rootCmd.PersistentFlags().BoolVarP(&yqlib.ConfiguredSecurityPreferences.DisableEnvOps, "security-disable-env-ops", "", false, "Disable env related operations.")
214214
rootCmd.PersistentFlags().BoolVarP(&yqlib.ConfiguredSecurityPreferences.DisableFileOps, "security-disable-file-ops", "", false, "Disable file related operations (e.g. load)")
215-
rootCmd.PersistentFlags().BoolVarP(&yqlib.ConfiguredSecurityPreferences.EnableSystemOps, "enable-system-operator", "", false, "Enable system operator to allow execution of external commands.")
215+
rootCmd.PersistentFlags().BoolVarP(&yqlib.ConfiguredSecurityPreferences.EnableSystemOps, "security-enable-system-operator", "", false, "Enable system operator to allow execution of external commands.")
216+
rootCmd.PersistentFlags().BoolVarP(&yqlib.ConfiguredSecurityPreferences.EnableSystemOps, "enable-system-operator", "", false, "DEPRECATED: use --security-enable-system-operator instead. Enable system operator to allow execution of external commands.")
217+
if err = rootCmd.MarkPersistentFlagDeprecated("enable-system-operator", "use --security-enable-system-operator instead."); err != nil {
218+
panic(err)
219+
}
216220

217221
rootCmd.AddCommand(
218222
createEvaluateSequenceCommand(),

pkg/yqlib/operator_system.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ func resolveCommandNode(commandNodes Context) (string, error) {
3333
if cmdNode.Kind != ScalarNode || cmdNode.Tag == "!!null" {
3434
return "", fmt.Errorf("system operator: command must be a string scalar")
3535
}
36+
if cmdNode.Value == "" {
37+
return "", fmt.Errorf("system operator: command must be a non-empty string")
38+
}
3639
return cmdNode.Value, nil
3740
}
3841

@@ -89,13 +92,11 @@ func systemOperator(d *dataTreeNavigator, context Context, expressionNode *Expre
8992
}
9093

9194
var stdin bytes.Buffer
92-
if candidate.Tag != "!!null" {
93-
encoded, err := encodeToYamlString(candidate)
94-
if err != nil {
95-
return Context{}, err
96-
}
97-
stdin.WriteString(encoded)
95+
encoded, err := encodeToYamlString(candidate)
96+
if err != nil {
97+
return Context{}, err
9898
}
99+
stdin.WriteString(encoded)
99100

100101
// #nosec G204 - intentional: user must explicitly enable this operator
101102
cmd := exec.Command(command, args...)

0 commit comments

Comments
 (0)