1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(perm): allow-net with port 80 (#21221)

This commit is contained in:
Ian Bull 2023-12-01 19:03:53 +01:00 committed by GitHub
parent fc8f060ee3
commit e087851e54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -559,8 +559,14 @@ impl FromStr for NetDescriptor {
type Err = AnyError; type Err = AnyError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let url = url::Url::parse(&format!("http://{s}"))?; // Set the scheme to `unknown` to parse the URL, as we really don't know
let hostname = url.host_str().unwrap().to_string(); // what the scheme is. We only using Url::parse to parse the host and port
// and don't care about the scheme.
let url = url::Url::parse(&format!("unknown://{s}"))?;
let hostname = url
.host_str()
.ok_or(url::ParseError::EmptyHost)?
.to_string();
Ok(NetDescriptor(hostname, url.port())) Ok(NetDescriptor(hostname, url.port()))
} }
@ -2273,7 +2279,9 @@ mod tests {
"github.com:3000", "github.com:3000",
"127.0.0.1", "127.0.0.1",
"172.16.0.2:8000", "172.16.0.2:8000",
"www.github.com:443" "www.github.com:443",
"80.example.com:80",
"443.example.com:443"
]), ]),
..Default::default() ..Default::default()
}) })
@ -2297,6 +2305,9 @@ mod tests {
("172.16.0.2", 0, false), ("172.16.0.2", 0, false),
("172.16.0.2", 6000, false), ("172.16.0.2", 6000, false),
("172.16.0.1", 8000, false), ("172.16.0.1", 8000, false),
("443.example.com", 444, false),
("80.example.com", 81, false),
("80.example.com", 80, true),
// Just some random hosts that should err // Just some random hosts that should err
("somedomain", 0, false), ("somedomain", 0, false),
("192.168.0.1", 0, false), ("192.168.0.1", 0, false),