File tree Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -350,17 +350,29 @@ impl EncodableCrate {
350
350
} ;
351
351
352
352
// 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) {
357
354
None
358
355
} else {
359
356
Some ( url)
360
357
}
361
358
}
362
359
}
363
360
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
+
364
376
#[ derive( Serialize , Deserialize , Debug ) ]
365
377
pub struct EncodableCrateLinks {
366
378
pub version_downloads : String ,
@@ -910,4 +922,11 @@ mod tests {
910
922
None
911
923
) ;
912
924
}
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
+ }
913
932
}
You can’t perform that action at this time.
0 commit comments