summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit/flash_test.ts12
-rw-r--r--ext/flash/lib.rs6
2 files changed, 17 insertions, 1 deletions
diff --git a/cli/tests/unit/flash_test.ts b/cli/tests/unit/flash_test.ts
index 4df225cbd..fdad1e3ae 100644
--- a/cli/tests/unit/flash_test.ts
+++ b/cli/tests/unit/flash_test.ts
@@ -36,6 +36,18 @@ function onListen<T>(
};
}
+Deno.test(async function httpServerInvalidHostname() {
+ assertThrows(
+ () =>
+ Deno.serve({
+ fetch: (_req) => new Response("ok"),
+ hostname: "localhost",
+ }),
+ TypeError,
+ "hostname could not be parsed as an IP address",
+ );
+});
+
Deno.test({ permissions: { net: true } }, async function httpServerBasic() {
const ac = new AbortController();
const promise = deferred();
diff --git a/ext/flash/lib.rs b/ext/flash/lib.rs
index de0a2231c..5d6275155 100644
--- a/ext/flash/lib.rs
+++ b/ext/flash/lib.rs
@@ -1244,7 +1244,11 @@ where
state
.borrow_mut::<P>()
.check_net(&(&opts.hostname, Some(opts.port)))?;
- let addr = SocketAddr::new(opts.hostname.parse()?, opts.port);
+ let parsed_hostname = opts
+ .hostname
+ .parse()
+ .map_err(|_| type_error("hostname could not be parsed as an IP address"))?;
+ let addr = SocketAddr::new(parsed_hostname, opts.port);
let (tx, rx) = mpsc::channel(100);
let (close_tx, close_rx) = mpsc::channel(1);
let (listening_tx, listening_rx) = mpsc::channel(1);