diff options
author | Marvin Hagemeister <marvin@deno.com> | 2024-09-06 11:22:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-06 09:22:52 +0000 |
commit | 73ab32c55124124467ce66eca2220bc4a5dfad0f (patch) | |
tree | 759b8d19b7e7f56c207658629de9cc46a0d06912 /tests/unit | |
parent | dcf155516b95ce540805eb04beec823cd079fa0f (diff) |
fix: invalid ipv6 hostname on `deno serve` (#25482)
This PR fixes an invalid URL being printed when running `deno serve`
Before: invalid URL
```sh
$ deno serve --host localhost
deno serve: Listening on http://::1:8000/
```
After: valid URL
```sh
$ deno serve --host localhost
deno serve: Listening on http://[::1]:8000/
```
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/serve_test.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index 19a8ccad1..9d23f8df2 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -872,6 +872,36 @@ Deno.test({ permissions: { net: true } }, async function validPortString() { await server.shutdown(); }); +Deno.test({ permissions: { net: true } }, async function ipv6Hostname() { + const ac = new AbortController(); + let url = ""; + + const consoleLog = console.log; + console.log = (msg) => { + try { + const match = msg.match(/Listening on (http:\/\/(.*?):(\d+)\/)/); + assert(!!match, `Didn't match ${msg}`); + url = match[1]; + } finally { + ac.abort(); + } + }; + + try { + const server = Deno.serve({ + handler: () => new Response(), + hostname: "::1", + port: 0, + signal: ac.signal, + }); + assertEquals(server.addr.transport, "tcp"); + assert(new URL(url), `Not a valid URL "${url}"`); + await server.shutdown(); + } finally { + console.log = consoleLog; + } +}); + Deno.test({ permissions: { net: true } }, function invalidPortFloat() { assertThrows( () => |