Skip to content

Commit 4fab87c

Browse files
committed
fix(shared): preserve escaped trailing whitespace in CLI arguments
1 parent 32ecd71 commit 4fab87c

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎packages/shared/src/cliArgs.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ describe("tokenizeCliArgs", () => {
2525
String.raw`--config model="gpt 5" --enable foo\ bar --config=profile='work profile'`,
2626
),
2727
).toEqual(["--config", "model=gpt 5", "--enable", "foo bar", "--config=profile=work profile"]);
28+
29+
for (const whitespace of [" ", "\t"]) {
30+
const args = `--add-dir /tmp/project\\${whitespace}`;
31+
expect(tokenizeCliArgs(args)).toEqual(["--add-dir", `/tmp/project${whitespace}`]);
32+
expect(tokenizeCliArgs(`${args} --verbose`)).toEqual([
33+
"--add-dir",
34+
`/tmp/project${whitespace}`,
35+
"--verbose",
36+
]);
37+
}
38+
});
39+
40+
it("ignores unescaped surrounding whitespace", () => {
41+
expect(tokenizeCliArgs(" \t\n")).toEqual([]);
42+
expect(tokenizeCliArgs(" \t--add-dir /tmp/project \t\n")).toEqual([
43+
"--add-dir",
44+
"/tmp/project",
45+
]);
2846
});
2947

3048
it("preserves literal backslashes in path values", () => {

‎packages/shared/src/cliArgs.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface ParseCliArgsOptions {
88
}
99

1010
export function tokenizeCliArgs(args?: string): ReadonlyArray<string> {
11-
const input = args?.trim();
11+
const input = args;
1212
if (!input) return [];
1313

1414
const tokens: string[] = [];

0 commit comments

Comments
 (0)