openclaw/src/daemon/arg-split.test.ts
2026-02-15 12:49:30 +00:00

37 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { splitArgsPreservingQuotes } from "./arg-split.js";
describe("splitArgsPreservingQuotes", () => {
it("splits on whitespace outside quotes", () => {
expect(splitArgsPreservingQuotes('/usr/bin/openclaw gateway start --name "My Bot"')).toEqual([
"/usr/bin/openclaw",
"gateway",
"start",
"--name",
"My Bot",
]);
});
it("supports systemd-style backslash escaping", () => {
expect(
splitArgsPreservingQuotes('openclaw --name "My \\"Bot\\"" --foo bar', {
escapeMode: "backslash",
}),
).toEqual(["openclaw", "--name", 'My "Bot"', "--foo", "bar"]);
});
it("supports schtasks-style escaped quotes while preserving other backslashes", () => {
expect(
splitArgsPreservingQuotes('openclaw --path "C:\\\\Program Files\\\\OpenClaw"', {
escapeMode: "backslash-quote-only",
}),
).toEqual(["openclaw", "--path", "C:\\\\Program Files\\\\OpenClaw"]);
expect(
splitArgsPreservingQuotes('openclaw --label "My \\"Quoted\\" Name"', {
escapeMode: "backslash-quote-only",
}),
).toEqual(["openclaw", "--label", 'My "Quoted" Name']);
});
});