From 0b9fbd7a7cdbde303b7d6038396fed7f040dcf2d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Feb 2026 23:05:09 +0000 Subject: [PATCH] Reject empty --cwd values in CLI parser Co-authored-by: Theo Browne --- apps/t3/src/cli.test.ts | 6 ++++++ apps/t3/src/cli.ts | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index f0f75d62e5..7f03e4377f 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -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", diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index ad7e718ef3..340a59b310 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -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; }