summaryrefslogtreecommitdiff
path: root/cli/args
diff options
context:
space:
mode:
Diffstat (limited to 'cli/args')
-rw-r--r--cli/args/flags.rs16
-rw-r--r--cli/args/flags_net.rs57
2 files changed, 46 insertions, 27 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 4d0465caa..710dbc0a6 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -7859,7 +7859,7 @@ mod tests {
let r = flags_from_vec(svec![
"deno",
"run",
- "--unsafely-ignore-certificate-errors=deno.land,localhost,::,127.0.0.1,[::1],1.2.3.4",
+ "--unsafely-ignore-certificate-errors=deno.land,localhost,[::],127.0.0.1,[::1],1.2.3.4",
"script.ts"
]);
assert_eq!(
@@ -7871,7 +7871,7 @@ mod tests {
unsafely_ignore_certificate_errors: Some(svec![
"deno.land",
"localhost",
- "::",
+ "[::]",
"127.0.0.1",
"[::1]",
"1.2.3.4"
@@ -7887,7 +7887,7 @@ mod tests {
let r = flags_from_vec(svec![
"deno",
"repl",
- "--unsafely-ignore-certificate-errors=deno.land,localhost,::,127.0.0.1,[::1],1.2.3.4"]);
+ "--unsafely-ignore-certificate-errors=deno.land,localhost,[::],127.0.0.1,[::1],1.2.3.4"]);
assert_eq!(
r.unwrap(),
Flags {
@@ -7899,7 +7899,7 @@ mod tests {
unsafely_ignore_certificate_errors: Some(svec![
"deno.land",
"localhost",
- "::",
+ "[::]",
"127.0.0.1",
"[::1]",
"1.2.3.4"
@@ -8091,7 +8091,7 @@ mod tests {
let r = flags_from_vec(svec![
"deno",
"run",
- "--allow-net=deno.land,deno.land:80,::,127.0.0.1,[::1],1.2.3.4:5678,:5678,[::1]:8080",
+ "--allow-net=deno.land,deno.land:80,[::],127.0.0.1,[::1],1.2.3.4:5678,:5678,[::1]:8080",
"script.ts"
]);
assert_eq!(
@@ -8104,7 +8104,7 @@ mod tests {
allow_net: Some(svec![
"deno.land",
"deno.land:80",
- "::",
+ "[::]",
"127.0.0.1",
"[::1]",
"1.2.3.4:5678",
@@ -8126,7 +8126,7 @@ mod tests {
let r = flags_from_vec(svec![
"deno",
"run",
- "--deny-net=deno.land,deno.land:80,::,127.0.0.1,[::1],1.2.3.4:5678,:5678,[::1]:8080",
+ "--deny-net=deno.land,deno.land:80,[::],127.0.0.1,[::1],1.2.3.4:5678,:5678,[::1]:8080",
"script.ts"
]);
assert_eq!(
@@ -8139,7 +8139,7 @@ mod tests {
deny_net: Some(svec![
"deno.land",
"deno.land:80",
- "::",
+ "[::]",
"127.0.0.1",
"[::1]",
"1.2.3.4:5678",
diff --git a/cli/args/flags_net.rs b/cli/args/flags_net.rs
index 2ea467056..57cf8d527 100644
--- a/cli/args/flags_net.rs
+++ b/cli/args/flags_net.rs
@@ -1,6 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use deno_core::url::Url;
+use deno_runtime::deno_permissions::NetDescriptor;
use std::net::IpAddr;
use std::str::FromStr;
@@ -42,21 +43,17 @@ pub fn validator(host_and_port: &str) -> Result<String, String> {
/// `127.0.0.1:port` and `localhost:port`.
pub fn parse(paths: Vec<String>) -> clap::error::Result<Vec<String>> {
let mut out: Vec<String> = vec![];
- for host_and_port in paths.iter() {
- if Url::parse(&format!("internal://{host_and_port}")).is_ok()
- || host_and_port.parse::<IpAddr>().is_ok()
- {
- out.push(host_and_port.to_owned())
- } else if let Ok(port) = host_and_port.parse::<BarePort>() {
+ for host_and_port in paths.into_iter() {
+ if let Ok(port) = host_and_port.parse::<BarePort>() {
// we got bare port, let's add default hosts
for host in ["0.0.0.0", "127.0.0.1", "localhost"].iter() {
out.push(format!("{}:{}", host, port.0));
}
} else {
- return Err(clap::Error::raw(
- clap::error::ErrorKind::InvalidValue,
- format!("Bad host:port pair: {host_and_port}"),
- ));
+ host_and_port.parse::<NetDescriptor>().map_err(|e| {
+ clap::Error::raw(clap::error::ErrorKind::InvalidValue, format!("{e:?}"))
+ })?;
+ out.push(host_and_port)
}
}
Ok(out)
@@ -121,8 +118,8 @@ mod tests {
let entries = svec![
"deno.land",
"deno.land:80",
- "::",
- "::1",
+ "[::]",
+ "[::1]",
"127.0.0.1",
"[::1]",
"1.2.3.4:5678",
@@ -142,8 +139,8 @@ mod tests {
let expected = svec![
"deno.land",
"deno.land:80",
- "::",
- "::1",
+ "[::]",
+ "[::1]",
"127.0.0.1",
"[::1]",
"1.2.3.4:5678",
@@ -174,10 +171,8 @@ mod tests {
#[test]
fn parse_net_args_ipv6() {
- let entries =
- svec!["::", "::1", "[::1]", "[::]:5678", "[::1]:5678", "::cafe"];
- let expected =
- svec!["::", "::1", "[::1]", "[::]:5678", "[::1]:5678", "::cafe"];
+ let entries = svec!["[::1]", "[::]:5678", "[::1]:5678"];
+ let expected = svec!["[::1]", "[::]:5678", "[::1]:5678"];
let actual = parse(entries).unwrap();
assert_eq!(actual, expected);
}
@@ -190,12 +185,36 @@ mod tests {
#[test]
fn parse_net_args_ipv6_error2() {
- let entries = svec!["0123:4567:890a:bcde:fg::"];
+ let entries = svec!["::1"];
assert!(parse(entries).is_err());
}
#[test]
fn parse_net_args_ipv6_error3() {
+ let entries = svec!["::"];
+ assert!(parse(entries).is_err());
+ }
+
+ #[test]
+ fn parse_net_args_ipv6_error4() {
+ let entries = svec!["::cafe"];
+ assert!(parse(entries).is_err());
+ }
+
+ #[test]
+ fn parse_net_args_ipv6_error5() {
+ let entries = svec!["1::1"];
+ assert!(parse(entries).is_err());
+ }
+
+ #[test]
+ fn parse_net_args_ipv6_error6() {
+ let entries = svec!["0123:4567:890a:bcde:fg::"];
+ assert!(parse(entries).is_err());
+ }
+
+ #[test]
+ fn parse_net_args_ipv6_error7() {
let entries = svec!["[::q]:8080"];
assert!(parse(entries).is_err());
}