Skip to content

Commit 61825b9

Browse files
committed
Fix documentation URL blocking for substring domains
1 parent 6526c0f commit 61825b9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/views.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use chrono::NaiveDateTime;
2+
use std::iter::{IntoIterator, Iterator};
23
use url::Url;
34

45
use crate::github;
@@ -361,11 +362,16 @@ impl EncodableCrate {
361362
fn domain_is_blocked(domain: &str) -> bool {
362363
DOCUMENTATION_BLOCKLIST
363364
.iter()
364-
.any(|blocked| domain_is_subdomain(domain, blocked))
365+
.any(|blocked| &domain == blocked || domain_is_subdomain(domain, blocked))
365366
}
366367

367368
fn domain_is_subdomain(potential_subdomain: &str, root: &str) -> bool {
368-
potential_subdomain.ends_with(root)
369+
if !potential_subdomain.ends_with(root) {
370+
return false;
371+
}
372+
373+
let root_with_prefix = format!(".{root}");
374+
potential_subdomain.ends_with(&root_with_prefix)
369375
}
370376

371377
#[derive(Serialize, Deserialize, Debug)]
@@ -917,4 +923,11 @@ mod tests {
917923
None
918924
);
919925
}
926+
927+
#[test]
928+
fn documentation_blocked_non_subdomain() {
929+
let input = Some(String::from("http://foorust-ci.org/"));
930+
let result = EncodableCrate::remove_blocked_documentation_urls(input);
931+
assert_some_eq!(result, "http://foorust-ci.org/");
932+
}
920933
}

0 commit comments

Comments
 (0)