Fix systemd ExecStart parsing whitespace

This commit is contained in:
Roshan Singh
2026-01-16 05:25:13 +00:00
parent 1656f491fd
commit fa9aafce83
2 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,38 @@
import { describe, expect, it } from "vitest";
import { parseSystemdExecStart } from "./systemd-unit.js";
describe("parseSystemdExecStart", () => {
it("splits on whitespace outside quotes", () => {
const execStart = "/usr/bin/clawdbot gateway start --foo bar";
expect(parseSystemdExecStart(execStart)).toEqual([
"/usr/bin/clawdbot",
"gateway",
"start",
"--foo",
"bar",
]);
});
it("preserves quoted arguments", () => {
const execStart = "/usr/bin/clawdbot gateway start --name \"My Bot\"";
expect(parseSystemdExecStart(execStart)).toEqual([
"/usr/bin/clawdbot",
"gateway",
"start",
"--name",
"My Bot",
]);
});
it("supports backslash-escaped characters", () => {
const execStart = "/usr/bin/clawdbot gateway start --path \/tmp\/clawdbot";
expect(parseSystemdExecStart(execStart)).toEqual([
"/usr/bin/clawdbot",
"gateway",
"start",
"--path",
"/tmp/clawdbot",
]);
});
});

View File

@@ -76,7 +76,7 @@ export function parseSystemdExecStart(value: string): string[] {
inQuotes = !inQuotes;
continue;
}
if (!inQuotes && /\\s/.test(char)) {
if (!inQuotes && /\s/.test(char)) {
if (current) {
args.push(current);
current = "";