Skip to content

Commit

Permalink
fix: clone parts to avoid mutating split parts (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuxhinDB authored Nov 29, 2024
1 parent cfe6dc1 commit b499e94
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions twistrs/src/permutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl Domain {
.chain(self.double_vowel_insertion())
.chain(self.keyword())
.chain(self.tld())
.chain(self.mapped())
.chain(self.homoglyph()?))
}

Expand Down Expand Up @@ -608,12 +609,12 @@ impl Domain {

for (key, values) in MAPPED_VALUES.entries() {
if self.domain.contains(key) {
let mut parts = self.domain.split(key);
let parts = self.domain.split(key);

for mapped_value in *values {
let result = format!(
"{domain}.{tld}",
domain = parts.join(mapped_value),
domain = parts.clone().join(mapped_value),
tld = self.tld
);

Expand Down Expand Up @@ -836,4 +837,18 @@ mod tests {

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

#[test]
fn test_mapped_generates_expected_permutation() {
let domain = Domain::new("trm.com").unwrap();
let expected = Domain::new("trnn.com").unwrap();

let results: Vec<Permutation> = domain
.mapped()
.into_iter()
.filter(|p| p.domain.fqdn == expected.fqdn)
.collect();

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

0 comments on commit b499e94

Please sign in to comment.