From e58bc3211385a675ae18cdc5bcf969aa420fee07 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 02:06:22 +0000 Subject: [PATCH] Trim whitespace in explicit CLI port values Co-authored-by: Theo Browne --- apps/t3/src/cli.test.ts | 10 ++++++++++ apps/t3/src/cli.ts | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index 651f1f5c23..3651f883f4 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -347,6 +347,16 @@ describe("parseCliOptions", () => { ); }); + it("trims whitespace in explicit port values", () => { + const options = parseCliOptions( + ["--backend-port", " 7001 ", "--web-port= 7002 "], + {}, + "/workspace", + ); + expect(options.backendPort).toBe(7001); + expect(options.webPort).toBe(7002); + }); + it("throws for out-of-range explicit port values", () => { expect(() => parseCliOptions(["--backend-port", "65536"], {}, "/workspace")).toThrow( "Invalid value for --backend-port", diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index a52228409a..5bf5d83a43 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -15,11 +15,12 @@ const TRUTHY_BOOLEAN_VALUES = new Set(["1", "true", "yes", "on"]); const FALSY_BOOLEAN_VALUES = new Set(["0", "false", "no", "off"]); function parseExplicitPort(value: string, key: string): number { - if (!/^\d+$/.test(value)) { + const normalized = value.trim(); + if (!/^\d+$/.test(normalized)) { throw new Error(`Invalid value for ${key}: '${value}'. Expected an integer between 1 and 65535.`); } - const parsed = Number.parseInt(value, 10); + const parsed = Number.parseInt(normalized, 10); if (!Number.isInteger(parsed) || parsed <= 0 || parsed > 65_535) { throw new Error(`Invalid value for ${key}: '${value}'. Expected an integer between 1 and 65535.`); }