mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
fix(flags): properly error out for urls (#25770)
Closes https://github.com/denoland/deno/issues/25760
This commit is contained in:
parent
92fc702cec
commit
3e053f8f06
2 changed files with 20 additions and 2 deletions
|
@ -5084,12 +5084,12 @@ fn permission_args_parse(
|
|||
}
|
||||
|
||||
if let Some(net_wl) = matches.remove_many::<String>("allow-net") {
|
||||
let net_allowlist = flags_net::parse(net_wl.collect()).unwrap();
|
||||
let net_allowlist = flags_net::parse(net_wl.collect())?;
|
||||
flags.permissions.allow_net = Some(net_allowlist);
|
||||
}
|
||||
|
||||
if let Some(net_wl) = matches.remove_many::<String>("deny-net") {
|
||||
let net_denylist = flags_net::parse(net_wl.collect()).unwrap();
|
||||
let net_denylist = flags_net::parse(net_wl.collect())?;
|
||||
flags.permissions.deny_net = Some(net_denylist);
|
||||
}
|
||||
|
||||
|
@ -10801,4 +10801,18 @@ mod tests {
|
|||
["foo,", "bar"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn net_flag_with_url() {
|
||||
let r = flags_from_vec(svec![
|
||||
"deno",
|
||||
"run",
|
||||
"--allow-net=https://example.com",
|
||||
"script.ts"
|
||||
]);
|
||||
assert_eq!(
|
||||
r.unwrap_err().to_string(),
|
||||
"error: invalid value 'https://example.com': URLs are not supported, only domains and ips"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -894,6 +894,10 @@ impl QueryDescriptor for NetDescriptor {
|
|||
// TODO(bartlomieju): rewrite to not use `AnyError` but a specific error implementations
|
||||
impl NetDescriptor {
|
||||
pub fn parse(hostname: &str) -> Result<Self, AnyError> {
|
||||
if hostname.starts_with("http://") || hostname.starts_with("https://") {
|
||||
return Err(uri_error(format!("invalid value '{hostname}': URLs are not supported, only domains and ips")));
|
||||
}
|
||||
|
||||
// If this is a IPv6 address enclosed in square brackets, parse it as such.
|
||||
if hostname.starts_with('[') {
|
||||
if let Some((ip, after)) = hostname.split_once(']') {
|
||||
|
|
Loading…
Reference in a new issue