From 8dd83d1f5c72904956afc0abc9e31fc408186dd7 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 00:48:00 +0000 Subject: [PATCH] Reject empty env port values in CLI parser Co-authored-by: Theo Browne --- apps/t3/src/cli.test.ts | 12 ++++++++++++ apps/t3/src/cli.ts | 9 +++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index 78af6fa84b..1fcfc4bbc8 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -217,6 +217,12 @@ describe("parseCliOptions", () => { ); }); + it("throws for empty environment port values", () => { + expect(() => parseCliOptions([], { T3_WEB_PORT: "" }, "/workspace")).toThrow( + "Invalid value for T3_WEB_PORT", + ); + }); + it("throws for out-of-range environment port values", () => { expect(() => parseCliOptions([], { T3_WEB_PORT: "65536" }, "/workspace")).toThrow( "Invalid value for T3_WEB_PORT", @@ -229,6 +235,12 @@ describe("parseCliOptions", () => { ); }); + it("throws for whitespace-only backend environment port values", () => { + expect(() => parseCliOptions([], { T3_BACKEND_PORT: " " }, "/workspace")).toThrow( + "Invalid value for T3_BACKEND_PORT", + ); + }); + it("throws for invalid backend environment port values", () => { expect(() => parseCliOptions([], { T3_BACKEND_PORT: "nope" }, "/workspace")).toThrow( "Invalid value for T3_BACKEND_PORT", diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index c7b1c4ba73..edd638a7cb 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -26,12 +26,17 @@ function parseEnvPort( key: string, fallback: number, ): { port: number; locked: boolean } { - if (!value) { + if (value === undefined) { return { port: fallback, locked: false }; } + const trimmed = value.trim(); + if (trimmed.length === 0) { + throw new Error(`Invalid value for ${key}: expected a non-empty port.`); + } + return { - port: parseExplicitPort(value, key), + port: parseExplicitPort(trimmed, key), locked: true, }; }