Skip to content

Commit

Permalink
fix: accept ipv6 as valid hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 7, 2023
1 parent 9dccfd9 commit d537a51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function _fmtOnHost(hostname: string | undefined) {
return hostname ? `on host ${JSON.stringify(hostname)}` : "on any host";
}

const HOSTNAME_RE = /^(?!-)[\d.A-Za-z-]{1,63}(?<!-)$/;
const HOSTNAME_RE = /^(?!-)[\d.:A-Za-z-]{1,63}(?<!-)$/;

export function _validateHostname(
hostname: string | undefined,
Expand Down
8 changes: 8 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ describe("getPort", () => {
expect(port3).not.toEqual(3001);
});
});

describe("ipv6", () => {
test("get port on ::1", async () => {
await blockPort(3000, "::1");
const port = await getPort({ host: "::1" });
expect(port).not.toBe(3000);
});
});
});

describe("random port", () => {
Expand Down

0 comments on commit d537a51

Please sign in to comment.