feat(unstable): --allow-net subdomain wildcards (#29327)

This commit is contained in:
Nayeem Rahman 2025-05-29 04:05:37 +01:00 committed by GitHub
parent cb23193f74
commit ab9673dcc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 377 additions and 54 deletions

View file

@ -5,6 +5,7 @@ use std::str::FromStr;
use deno_core::url::Url;
use deno_runtime::deno_permissions::NetDescriptor;
use deno_runtime::deno_permissions::UnstableSubdomainWildcards;
#[derive(Debug, PartialEq, Eq)]
pub struct ParsePortError(String);
@ -32,7 +33,11 @@ pub fn validator(host_and_port: &str) -> Result<String, String> {
if Url::parse(&format!("internal://{host_and_port}")).is_ok()
|| host_and_port.parse::<IpAddr>().is_ok()
|| host_and_port.parse::<BarePort>().is_ok()
|| NetDescriptor::parse(host_and_port).is_ok()
|| NetDescriptor::parse_for_list(
host_and_port,
UnstableSubdomainWildcards::Enabled,
)
.is_ok()
{
Ok(host_and_port.to_string())
} else {
@ -52,7 +57,11 @@ pub fn parse(paths: Vec<String>) -> clap::error::Result<Vec<String>> {
out.push(format!("{}:{}", host, port.0));
}
} else {
NetDescriptor::parse(&host_and_port).map_err(|e| {
NetDescriptor::parse_for_list(
&host_and_port,
UnstableSubdomainWildcards::Enabled,
)
.map_err(|e| {
clap::Error::raw(clap::error::ErrorKind::InvalidValue, e.to_string())
})?;
out.push(host_and_port)
@ -120,6 +129,7 @@ mod tests {
let entries = svec![
"deno.land",
"deno.land:80",
"*.deno.land",
"[::]",
"[::1]",
"127.0.0.1",
@ -141,6 +151,7 @@ mod tests {
let expected = svec![
"deno.land",
"deno.land:80",
"*.deno.land",
"[::]",
"[::1]",
"127.0.0.1",