fix: harden powershell wrapper detection

This commit is contained in:
Peter Steinberger
2026-03-13 20:37:29 +00:00
parent e2fa47f5f2
commit 28a49aaa34
4 changed files with 20 additions and 0 deletions

View File

@@ -22,6 +22,21 @@ describe("resolveInlineCommandMatch", () => {
command: "Get-ChildItem",
valueTokenIndex: 2,
});
expect(
resolveInlineCommandMatch(["pwsh", "-File", "script.ps1"], POWERSHELL_INLINE_COMMAND_FLAGS),
).toEqual({
command: "script.ps1",
valueTokenIndex: 2,
});
expect(
resolveInlineCommandMatch(
["powershell", "-f", "script.ps1"],
POWERSHELL_INLINE_COMMAND_FLAGS,
),
).toEqual({
command: "script.ps1",
valueTokenIndex: 2,
});
});
it("supports combined -c forms only when enabled", () => {

View File

@@ -3,6 +3,8 @@ export const POWERSHELL_INLINE_COMMAND_FLAGS = new Set([
"-c",
"-command",
"--command",
"-f",
"-file",
"-encodedcommand",
"-enc",
"-e",

View File

@@ -55,6 +55,8 @@ describe("system run command helpers", () => {
test("extractShellCommandFromArgv supports fish and pwsh wrappers", () => {
expect(extractShellCommandFromArgv(["fish", "-c", "echo hi"])).toBe("echo hi");
expect(extractShellCommandFromArgv(["pwsh", "-Command", "Get-Date"])).toBe("Get-Date");
expect(extractShellCommandFromArgv(["pwsh", "-File", "script.ps1"])).toBe("script.ps1");
expect(extractShellCommandFromArgv(["powershell", "-f", "script.ps1"])).toBe("script.ps1");
expect(extractShellCommandFromArgv(["pwsh", "-EncodedCommand", "ZQBjAGgAbwA="])).toBe(
"ZQBjAGgAbwA=",
);