Reject empty --cwd values in CLI parser

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-09 23:05:09 +00:00
1 parent 6185784ea2
commit 0b9fbd7a7c
2 files changed
+17 -2

No files matched your search

+6
View File
@@ -86,6 +86,12 @@ describe("parseCliOptions", () => {
);
});
it("throws for empty cwd flag values", () => {
expect(() => parseCliOptions(["--cwd="], {}, "/workspace")).toThrow(
"Invalid value for --cwd",
);
});
it("throws for unknown arguments", () => {
expect(() => parseCliOptions(["--wat"], {}, "/workspace")).toThrow(
"Unknown argument: --wat",
+11 -2
View File
@@ -36,6 +36,15 @@ function parseEnvPort(
};
}
function parseExplicitPath(value: string, key: string): string {
const trimmed = value.trim();
if (trimmed.length === 0) {
throw new Error(`Invalid value for ${key}: expected a non-empty path.`);
}
return path.resolve(trimmed);
}
interface CliOptions {
backendPort: number;
webPort: number;
@@ -152,12 +161,12 @@ export function parseCliOptions(
}
if (arg.startsWith("--cwd=")) {
launchCwd = path.resolve(arg.split("=")[1] ?? cwd);
launchCwd = parseExplicitPath(arg.split("=")[1] ?? "", "--cwd");
continue;
}
if (arg === "--cwd") {
launchCwd = path.resolve(readArgValue(argv, index, "--cwd"));
launchCwd = parseExplicitPath(readArgValue(argv, index, "--cwd"), "--cwd");
index += 1;
continue;
}