Skip to content

Commit 2a03436

Browse files
authored
fix(dns): fold domain case as ASCII, matching the reverse-DNS parser (#2723)
1 parent 791c8b5 commit 2a03436

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

crates/api-db/src/dns/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pub mod resource_record;
2222
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
2323

2424
pub fn normalize_domain(name: &str) -> String {
25-
let normalize_domain = name.trim_end_matches('.').to_lowercase();
26-
tracing::debug!("Normalized domain name: {} to: {}", name, normalize_domain);
27-
normalize_domain
25+
let normalized_domain = name.trim_end_matches('.').to_ascii_lowercase();
26+
tracing::debug!(input = %name, normalized = %normalized_domain, "normalized domain name");
27+
normalized_domain
2828
}
2929

3030
/// Parse a reverse-DNS (PTR) query name into the address it points at -- the
@@ -77,10 +77,16 @@ mod tests {
7777

7878
#[test]
7979
fn test_normalize_domain_name() {
80-
let domain_name = "example.com.";
81-
let expected = "example.com";
82-
let normalized = super::normalize_domain(domain_name);
83-
assert_eq!(normalized, expected);
80+
use carbide_test_support::value_scenarios;
81+
82+
value_scenarios!(
83+
run = |name: &str| super::normalize_domain(name);
84+
"strips the trailing dot and folds case to ASCII lowercase" {
85+
"example.com." => "example.com".to_string(),
86+
"EXAMPLE.COM." => "example.com".to_string(),
87+
"Example.Com" => "example.com".to_string(),
88+
}
89+
);
8490
}
8591

8692
#[test]

0 commit comments

Comments
 (0)