Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime): Improve Error Handling and-Dot Handling in-fqdn! Macro (closed) #23590

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
91b438e
Implement improvements for error handling and dot handling in fqdn! m…
yazan-nidal Apr 28, 2024
01b8f01
add tests for modified fqdn
yazan-nidal Apr 29, 2024
cc8a798
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal Apr 29, 2024
3aa5ca0
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal Apr 29, 2024
ea3cc59
Implement improvements(v2) for error handling and dot handling in fqd…
yazan-nidal May 6, 2024
2fbaf97
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal May 6, 2024
f8bfa41
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal May 7, 2024
589d407
add failed parse domain tests
yazan-nidal May 7, 2024
9e373ce
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal May 7, 2024
1bbf516
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal May 8, 2024
114cc7a
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
bartlomieju May 9, 2024
694aa25
fmt
bartlomieju May 9, 2024
92a9509
Fix lint issues
yazan-nidal May 9, 2024
d7a541d
fmt
yazan-nidal May 9, 2024
c74d45f
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal May 12, 2024
1bbc4f6
Merge branch 'denoland:main' into fix-(runtime)-Improve-Error-Handlin…
yazan-nidal May 13, 2024
166d117
fix: improve parsing of IPv6, IPv4, hostnames, and URLs; make port op…
yazan-nidal May 23, 2024
6f8664b
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal May 23, 2024
40fe3bb
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
dsherret May 23, 2024
816b410
Merge branch 'fix-(runtime)-Improve-Error-Handling-and-Dot-Handling-i…
yazan-nidal May 27, 2024
dd15f60
enhancing
yazan-nidal May 27, 2024
2179fe8
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal May 27, 2024
49c4053
update Cargo.lock
bartlomieju May 27, 2024
e7a41b0
fmt
bartlomieju May 27, 2024
b4b84ab
fmt#
yazan-nidal May 28, 2024
5c63b47
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal May 28, 2024
d704574
fmt#
yazan-nidal May 28, 2024
3008de6
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal May 28, 2024
233111f
Merge branch 'fix-(runtime)-Improve-Error-Handling-and-Dot-Handling-i…
yazan-nidal May 28, 2024
8b8e240
fmt
yazan-nidal May 29, 2024
58efbb5
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
yazan-nidal May 29, 2024
932efa7
fmt#
yazan-nidal May 29, 2024
68c6104
Merge branch 'fix-(runtime)-Improve-Error-Handling-and-Dot-Handling-i…
yazan-nidal May 29, 2024
280035e
Merge branch 'main' into fix-(runtime)-Improve-Error-Handling-and-Dot…
dsherret May 30, 2024
05c6689
lint
yazan-nidal May 30, 2024
390b79c
Merge remote-tracking branch 'origin/fix-(runtime)-Improve-Error-Hand…
yazan-nidal May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ faster-hex = "0.9"
fastwebsockets = { version = "0.6", features = ["upgrade", "unstable-split"] }
filetime = "0.2.16"
flate2 = { version = "1.0.26", default-features = false }
fqdn = "0.3.4"
fs3 = "0.5.0"
futures = "0.3.21"
glob = "0.3.1"
Expand Down
39 changes: 39 additions & 0 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9789,4 +9789,43 @@ mod tests {
}
);
}

#[test]
fn wildcard_flags() {
#[rustfmt::skip]
let r = flags_from_vec(svec![
"deno",
"run",
"--allow-read",
"--allow-write=notion-next",
"--allow-net=api.notion.com,*.amazonaws.com",
"--allow-env",
"script.ts"
]);

let flags = r.unwrap();
assert_eq!(
flags,
Flags {
subcommand: DenoSubcommand::Run(RunFlags::new_default(
"script.ts".to_string()
)),
permissions: PermissionFlags {
allow_env: Some(vec![],),
allow_net: Some(vec![
"api.notion.com".to_string(),
"*.amazonaws.com".to_string(),
],),
allow_read: Some(vec![],),
allow_write: Some(vec!["notion-next".to_string(),],),
..Default::default()
},
unstable_config: UnstableConfig {
..Default::default()
},
code_cache_enabled: true,
..Flags::default()
}
);
}
}
1 change: 1 addition & 0 deletions ext/net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ path = "lib.rs"
[dependencies]
deno_core.workspace = true
deno_tls.workspace = true
fqdn.workspace = true
pin-project.workspace = true
rustls-tokio-stream.workspace = true
serde.workspace = true
Expand Down
85 changes: 85 additions & 0 deletions ext/net/host.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use fqdn::FQDN;
use std::fmt;
use std::net::Ipv4Addr;
use std::net::Ipv6Addr;
use std::str::FromStr;

#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub enum Host {
FQDN(FQDN),
Ipv4(Ipv4Addr),
Ipv6(Ipv6Addr),
}

impl Host {
pub fn from_host_and_origin_host(
host: &str,
origin_host: &str,
) -> Result<Self, AnyError> {
if let Ok(ipv6) = host.parse::<Ipv6Addr>() {
return Ok(Host::Ipv6(ipv6));
}

let host = FQDN::from_str(host)
.with_context(|| format!("Failed to parse host: {}\n", origin_host))?;
let host_string = host.to_string();

if let Ok(ipv4) = host_string.parse::<Ipv4Addr>() {
return Ok(Host::Ipv4(ipv4));
}

Ok(Host::FQDN(host))
}
}

impl fmt::Display for Host {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Host::FQDN(fqdn) => write!(f, "{}", fqdn),
Host::Ipv4(ipv4) => write!(f, "{}", ipv4),
Host::Ipv6(ipv6) => write!(f, "[{}]", ipv6),
}
}
}

pub fn split_host_port(s: &str) -> Result<(String, Option<u16>), AnyError> {
let mut host = s.to_string();
let mut port = None;

let have_port = host.contains(':') && !host.contains('[');

if host.starts_with('[') && host.contains(']') {
if host.ends_with("]:") {
return Err(AnyError::msg("Invalid format: [ipv6]:port"));
}
if let Some(pos) = host.rfind("]:") {
let port_str = &host[pos + 2..];
let port_ = port_str.parse::<u16>().ok();
host = host[1..pos].to_string();
port = port_;
} else {
host = host[1..(host.len() - 1)].to_string();
}
} else if let Some(pos) = host.rfind(':') {
let port_str = &host[pos + 1..];
if let Ok(parsed_port) = port_str.parse::<u16>() {
host.truncate(pos);
port = Some(parsed_port);
}
}

if have_port && port.is_none() {
return Err(AnyError::msg("No port specified after ':'"));
}

Ok((host, port))
}

pub fn extract_host(s: &str) -> String {
if let Some(index) = s.find("://") {
return s[index + 3..].split('/').next().unwrap_or(s).to_string();
}
s.to_string()
}