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
Changes from 4 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
69 changes: 68 additions & 1 deletion runtime/permissions/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use deno_core::url;
use deno_core::url::Url;
use deno_core::ModuleSpecifier;
use deno_terminal::colors;
use fqdn::fqdn;
use fqdn::FQDN;
use once_cell::sync::Lazy;
use std::borrow::Cow;
Expand Down Expand Up @@ -688,6 +687,28 @@ impl Descriptor for WriteDescriptor {
}
}

/// Modify `fqdn!` to handle domain names ending with a dot
/// Handle parsing error
macro_rules! fqdn {
($($args:expr),*) => {{
#[allow(unused_mut)]
let mut str = std::string::String::new();
$( str += "."; str += $args; )*


let fqdn_string = if str.ends_with('.') {
&str[1..str.len() - 1]
} else {
&str[1..]
};

match fqdn_string.parse::<$crate::FQDN>() {
Ok(fqdn) => fqdn,
Err(_) => $crate::FQDN::default(),
yazan-nidal marked this conversation as resolved.
Show resolved Hide resolved
}
}}
}

#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct NetDescriptor(pub FQDN, pub Option<u16>);

Expand Down Expand Up @@ -3293,4 +3314,50 @@ mod tests {
)
.is_err());
}

#[test]
fn test_from_str_valid() {
let input = "example.com:8080";
let expected_fqdn = fqdn!("example.com");
let expected_port = Some(8080);
let result = NetDescriptor::from_str(input).unwrap();
assert_eq!(result.0, expected_fqdn);
assert_eq!(result.1, expected_port);
}

#[test]
fn test_from_str_invalid_empty() {
let input = "";
assert!(NetDescriptor::from_str(input).is_err());
}

#[test]
fn test_from_str_invalid_no_host() {
let input = ":8080";
assert!(NetDescriptor::from_str(input).is_err());
}

#[test]
fn test_macro_expansion() {
let host = "example.com";
let port = Some(8080);
let descriptor_tuple: (&str, Option<u16>) = (host, port);
let descriptor = NetDescriptor::new(&&descriptor_tuple);
assert_eq!(descriptor.0, fqdn!("example.com."));
assert_eq!(descriptor.1, Some(8080));
}

#[test]
fn test_parse_with_unknown_scheme() {
let input = "example.com:8080";
let descriptor = NetDescriptor::from_str(input).unwrap();
assert_eq!(descriptor.0, fqdn!("example.com."));
assert_eq!(descriptor.1, Some(8080));
}

#[test]
fn test_from_str_invalid_unparsable() {
let input = "foo@bar.com.";
assert_eq!(fqdn!(input), crate::FQDN::default());
}
}