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(tlds): include extended tlds within tld scope #79

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions twistrs/src/permutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,18 +584,20 @@ impl Domain {
/// Permutation method that replaces all TLDs as variations of the
/// root domain passed.
pub fn tld(&self) -> impl Iterator<Item = Permutation> + '_ {
TLDS.iter().filter_map(move |tld| {
let fqdn = format!("{}.{}", &self.domain, tld);
TLDS.iter()
.chain(TLDS_EXTENDED.iter())
.filter_map(move |tld| {
let fqdn = format!("{}.{}", &self.domain, tld);

if let Ok(domain) = Domain::new(fqdn.as_str()) {
return Some(Permutation {
domain,
kind: PermutationKind::Tld,
});
}
if let Ok(domain) = Domain::new(fqdn.as_str()) {
return Some(Permutation {
domain,
kind: PermutationKind::Tld,
});
}

None
})
None
})
}

/// Permutation method that maps one or more characters into another
Expand Down Expand Up @@ -816,4 +818,22 @@ mod tests {

assert_eq!(results.len(), 1);
}

#[test]
fn regression_test_co_uk_tld_is_valid() {
// Ensure we do not miss two-level TLDs such as .co.uk
let domain = Domain::new("bbc.com").unwrap();
let expected = [
Domain::new("bbc.co.uk").unwrap().fqdn,
Domain::new("bbc.co.rs").unwrap().fqdn,
Domain::new("bbc.co.uz").unwrap().fqdn,
];

let results: Vec<Permutation> = domain
.tld()
.filter(|p| expected.contains(&p.domain.fqdn))
.collect();

assert_eq!(results.len(), 3);
}
}
Loading