mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 09:47:28 +00:00
fix: harden powershell wrapper detection
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
@@ -3,6 +3,8 @@ export const POWERSHELL_INLINE_COMMAND_FLAGS = new Set([
|
||||
"-c",
|
||||
"-command",
|
||||
"--command",
|
||||
"-f",
|
||||
"-file",
|
||||
"-encodedcommand",
|
||||
"-enc",
|
||||
"-e",
|
||||
|
||||
@@ -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=",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user