add support for inverting whitelist

This commit is contained in:
Sunshine 2022-08-29 18:22:12 -04:00
parent e89b79492b
commit 116c556e09
No known key found for this signature in database
GPG key ID: B80CA68703CD8AB1
2 changed files with 18 additions and 7 deletions

View file

@ -53,7 +53,7 @@ impl Options {
.args_from_usage("-c, --no-css 'Removes CSS'") .args_from_usage("-c, --no-css 'Removes CSS'")
.args_from_usage("-C, --charset=[UTF-8] 'Enforces custom encoding'") .args_from_usage("-C, --charset=[UTF-8] 'Enforces custom encoding'")
.args_from_usage( .args_from_usage(
"-D, --domains=[bad.org,ads.site,0.0.0.0,127.0.0.0:8080] 'Whitelist of domains'", "-D, --domains=[bad.org,ads.site,127.0.0.0:8080] 'Whitelist of domains'",
) )
.args_from_usage("-e, --ignore-errors 'Ignore network errors'") .args_from_usage("-e, --ignore-errors 'Ignore network errors'")
.args_from_usage("-E, --exclude-domains 'Treat list of specified domains as blacklist'") .args_from_usage("-E, --exclude-domains 'Treat list of specified domains as blacklist'")

View file

@ -266,12 +266,23 @@ pub fn retrieve_asset(
"".to_string(), "".to_string(),
)) ))
} else { } else {
if let Some(domains) = &options.domains { if options.exclude_domains {
if domains if let Some(domains) = &options.domains {
.iter() if domains
.any(|d| domain_is_within_domain(url.host_str().unwrap(), &d.trim())) .iter()
{ .any(|d| domain_is_within_domain(url.host_str().unwrap(), &d.trim()))
return Err(client.get("").send().unwrap_err()); {
return Err(client.get("").send().unwrap_err());
}
}
} else {
if let Some(domains) = &options.domains {
if domains
.iter()
.any(|d| !domain_is_within_domain(url.host_str().unwrap(), &d.trim()))
{
return Err(client.get("").send().unwrap_err());
}
} }
} }