diff --git a/src/client/proxy/matcher.rs b/src/client/proxy/matcher.rs index a883133e..037cf278 100644 --- a/src/client/proxy/matcher.rs +++ b/src/client/proxy/matcher.rs @@ -515,7 +515,10 @@ impl DomainMatcher { fn contains(&self, domain: &str) -> bool { let domain_len = domain.len(); for d in &self.0 { - if d == domain || d.strip_prefix('.') == Some(domain) { + if d == domain + || d.strip_prefix('.') + .map_or(false, |s| s.eq_ignore_ascii_case(domain)) + { return true; } else if domain.ends_with(d) { if d.starts_with('.') { @@ -866,4 +869,33 @@ mod tests { assert!(m.intercept(&"http://rick.roll".parse().unwrap()).is_none()); } + + #[test] + fn test_domain_matcher_case_insensitive() { + let domains = vec![".foo.bar".into()]; + let matcher = DomainMatcher(domains); + + assert!(matcher.contains("foo.bar")); + assert!(matcher.contains("FOO.BAR")); + assert!(matcher.contains("Foo.Bar")); + } + + #[test] + fn test_no_proxy_case_insensitive() { + let p = p! { + all = "http://proxy.local", + no = ".example.com", + }; + + // should bypass proxy (case insensitive match) + assert!(p + .intercept(&"http://example.com".parse().unwrap()) + .is_none()); + assert!(p + .intercept(&"http://EXAMPLE.COM".parse().unwrap()) + .is_none()); + assert!(p + .intercept(&"http://Example.com".parse().unwrap()) + .is_none()); + } }