Skip to content

Commit 05bb07d

Browse files
authored
Merge pull request #5503 from Turbo87/domain-block
Fix documentation URL blocking for substring domains
2 parents 4a50f98 + 65ab263 commit 05bb07d

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/views.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,17 +350,29 @@ impl EncodableCrate {
350350
};
351351

352352
// Match documentation URL host against blocked host array elements
353-
if DOCUMENTATION_BLOCKLIST
354-
.iter()
355-
.any(|blocked| url_host.ends_with(blocked))
356-
{
353+
if domain_is_blocked(url_host) {
357354
None
358355
} else {
359356
Some(url)
360357
}
361358
}
362359
}
363360

361+
fn domain_is_blocked(domain: &str) -> bool {
362+
DOCUMENTATION_BLOCKLIST
363+
.iter()
364+
.any(|blocked| &domain == blocked || domain_is_subdomain(domain, blocked))
365+
}
366+
367+
fn domain_is_subdomain(potential_subdomain: &str, root: &str) -> bool {
368+
if !potential_subdomain.ends_with(root) {
369+
return false;
370+
}
371+
372+
let root_with_prefix = format!(".{root}");
373+
potential_subdomain.ends_with(&root_with_prefix)
374+
}
375+
364376
#[derive(Serialize, Deserialize, Debug)]
365377
pub struct EncodableCrateLinks {
366378
pub version_downloads: String,
@@ -910,4 +922,11 @@ mod tests {
910922
None
911923
);
912924
}
925+
926+
#[test]
927+
fn documentation_blocked_non_subdomain() {
928+
let input = Some(String::from("http://foorust-ci.org/"));
929+
let result = EncodableCrate::remove_blocked_documentation_urls(input);
930+
assert_some_eq!(result, "http://foorust-ci.org/");
931+
}
913932
}

0 commit comments

Comments
 (0)