diff --git a/README.md b/README.md index ed3f9ff..049e80f 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ cat index.html | monolith -aIiFfcMv -b https://original.site/ - > result.html - `-C`: Save document using custom `charset` - `-d`: Allow retrieving assets only from specified `domain(s)` - `-e`: Ignore network errors - - `-E`: Exclude all assets located within domains specified in whitelist + - `-E`: Avoid retrieving assets located within specified domains - `-f`: Omit frames - `-F`: Exclude web fonts - `-i`: Remove images diff --git a/src/utils.rs b/src/utils.rs index 078a6f0..f3996c2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -117,8 +117,8 @@ pub fn domain_is_within_domain(domain: &str, domain_to_match_against: &str) -> b while i < l { // Exit and return false if went out of bounds of domain to match against, and it didn't start with a dot - if domain_to_match_against_partials.len() < i + 1 - && !domain_to_match_against_starts_with_a_dot + if !domain_to_match_against_starts_with_a_dot + && domain_to_match_against_partials.len() < i + 1 { ok = false; break; @@ -135,10 +135,9 @@ pub fn domain_is_within_domain(domain: &str, domain_to_match_against: &str) -> b domain_to_match_against_partials.get(i).unwrap() }; - let parts_match = domain_to_match_against_starts_with_a_dot - || domain_to_match_against_partial.eq_ignore_ascii_case(domain_partial); + let parts_match = domain_to_match_against_partial.eq_ignore_ascii_case(domain_partial); - if !parts_match { + if !parts_match && domain_to_match_against_partial.len() != 0 { ok = false; break; } diff --git a/tests/utils/domain_is_within_domain.rs b/tests/utils/domain_is_within_domain.rs index fcd0840..dc843f4 100644 --- a/tests/utils/domain_is_within_domain.rs +++ b/tests/utils/domain_is_within_domain.rs @@ -134,6 +134,14 @@ mod failing { )); } + #[test] + fn different_domain_is_not_within_dotted_domain() { + assert!(!utils::domain_is_within_domain( + "www.doodleoptimize.com", + ".ycombinator.com" + )); + } + #[test] fn no_domain_can_be_within_empty_domain() { assert!(!utils::domain_is_within_domain("ycombinator.com", ""));