Reject empty env port values in CLI parser
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
f86860cff2
commit
8dd83d1f5c
2 files changed
+19
-2
No files matched your search
@@ -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",
|
||||
|
||||
+7
-2
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user