Require decimal-only CLI port values

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 01:30:53 +00:00
1 parent 5badab515f
commit 0a1a0c0a27
2 files changed
+17 -1

No files matched your search

+12
View File
@@ -224,6 +224,12 @@ describe("parseCliOptions", () => {
);
});
it("rejects non-decimal explicit port values", () => {
expect(() => parseCliOptions(["--backend-port", "0x10"], {}, "/workspace")).toThrow(
"Invalid value for --backend-port",
);
});
it("throws for out-of-range explicit port values", () => {
expect(() => parseCliOptions(["--backend-port", "65536"], {}, "/workspace")).toThrow(
"Invalid value for --backend-port",
@@ -284,6 +290,12 @@ describe("parseCliOptions", () => {
);
});
it("rejects non-decimal environment port values", () => {
expect(() => parseCliOptions([], { T3_WEB_PORT: "1e3" }, "/workspace")).toThrow(
"Invalid value for T3_WEB_PORT",
);
});
it("throws for empty environment port values", () => {
expect(() => parseCliOptions([], { T3_WEB_PORT: "" }, "/workspace")).toThrow(
"Invalid value for T3_WEB_PORT",
+5 -1
View File
@@ -13,7 +13,11 @@ const DEFAULT_WEB_PORT = 4318;
const DEFAULT_CLI_VERSION = "0.1.0";
function parseExplicitPort(value: string, key: string): number {
const parsed = Number(value);
if (!/^\d+$/.test(value)) {
throw new Error(`Invalid value for ${key}: '${value}'. Expected an integer between 1 and 65535.`);
}
const parsed = Number.parseInt(value, 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.`);
}