Skip to content

Commit

Permalink
Implement improvements for error handling and dot handling in fqdn! m…
Browse files Browse the repository at this point in the history
…acro

This commit addresses issue denoland#23294 by enhancing the error handling and dot handling logic within the fqdn! macro. Specifically, it:
- Handles parsing errors gracefully using pattern matching instead of unwrap().
- Adjusts substring parsing to correctly handle domain names ending with a dot.

This change improves the reliability and robustness of the fqdn! macro, ensuring more accurate parsing of fully qualified domain names.

Fixes: denoland#23294
  • Loading branch information
yazan-nidal committed Apr 28, 2024
1 parent 021a0dc commit 91b438e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions runtime/permissions/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,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(),
}
}}
}

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

Expand Down

0 comments on commit 91b438e

Please sign in to comment.