From 0de0fb45833e33198bf70c64e84f203e9f3c89b7 Mon Sep 17 00:00:00 2001 From: Jendrik <12938023+jendrikw@users.noreply.github.com> Date: Sun, 20 Nov 2022 17:42:36 +0100 Subject: [PATCH] extend doc url blocks to arbitrary subdomains As discussed at https://rust-lang.zulipchat.com/#narrow/stream/318791-t-crates-io/topic/link.20to.20scam/near/311155912 --- src/views.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/views.rs b/src/views.rs index 3bc62ff7419..bfa33b30255 100644 --- a/src/views.rs +++ b/src/views.rs @@ -350,7 +350,10 @@ impl EncodableCrate { }; // Match documentation URL host against blocked host array elements - if DOCUMENTATION_BLOCKLIST.contains(&url_host) { + if DOCUMENTATION_BLOCKLIST + .iter() + .any(|blocked| url_host.ends_with(blocked)) + { None } else { Some(url) @@ -897,4 +900,14 @@ mod tests { None ); } + + #[test] + fn documentation_blocked_subdomain() { + assert_eq!( + EncodableCrate::remove_blocked_documentation_urls(Some(String::from( + "http://www.rust-ci.org/crate/crate-0.1/doc/crate-0.1", + ),),), + None + ); + } }