From 905f8c98268988493ce0be6626c9cfb9c445465c Mon Sep 17 00:00:00 2001 From: twangboy Date: Wed, 16 Oct 2024 13:30:17 -0600 Subject: [PATCH] Add try to the keywords list --- salt/modules/cmdmod.py | 2 +- tests/pytests/unit/modules/test_cmdmod.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index fe1d4412d00..5ec3a6f6a45 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -293,7 +293,7 @@ def _prep_powershell_cmd(win_shell, cmd, encoded_cmd): # Commands that are a specific keyword behave differently. They fail if # you add a "&" to the front. Add those here as we find them: - keywords = ["$", "&", ".", "Configuration"] + keywords = ["$", "&", ".", "Configuration", "try"] for keyword in keywords: if cmd.startswith(keyword): diff --git a/tests/pytests/unit/modules/test_cmdmod.py b/tests/pytests/unit/modules/test_cmdmod.py index e1f2a604cd1..10d154b98d2 100644 --- a/tests/pytests/unit/modules/test_cmdmod.py +++ b/tests/pytests/unit/modules/test_cmdmod.py @@ -1064,6 +1064,7 @@ def test_prep_powershell_cmd_no_powershell(): [ ("Write-Host foo", "& Write-Host foo"), ("$PSVersionTable", "$PSVersionTable"), + ("try {this} catch {that}", "try {this} catch {that}"), ], ) def test_prep_powershell_cmd(cmd, parsed):