Trim whitespace in explicit CLI port values

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 02:06:22 +00:00
1 parent bc65ad73aa
commit e58bc32113
2 files changed
+13 -2

No files matched your search

+10
View File
@@ -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",
+3 -2
View File
@@ -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.`);
}