Skip to content

Commit 1b3fa96

Browse files
authored
fix(matcher): improve domain matching case insensitivity (#251)
Make NO_PROXY domain matching case-insensitive
1 parent d574011 commit 1b3fa96

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/client/proxy/matcher.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,10 @@ impl DomainMatcher {
515515
fn contains(&self, domain: &str) -> bool {
516516
let domain_len = domain.len();
517517
for d in &self.0 {
518-
if d == domain || d.strip_prefix('.') == Some(domain) {
518+
if d == domain
519+
|| d.strip_prefix('.')
520+
.map_or(false, |s| s.eq_ignore_ascii_case(domain))
521+
{
519522
return true;
520523
} else if domain.ends_with(d) {
521524
if d.starts_with('.') {
@@ -866,4 +869,33 @@ mod tests {
866869

867870
assert!(m.intercept(&"http://rick.roll".parse().unwrap()).is_none());
868871
}
872+
873+
#[test]
874+
fn test_domain_matcher_case_insensitive() {
875+
let domains = vec![".foo.bar".into()];
876+
let matcher = DomainMatcher(domains);
877+
878+
assert!(matcher.contains("foo.bar"));
879+
assert!(matcher.contains("FOO.BAR"));
880+
assert!(matcher.contains("Foo.Bar"));
881+
}
882+
883+
#[test]
884+
fn test_no_proxy_case_insensitive() {
885+
let p = p! {
886+
all = "http://proxy.local",
887+
no = ".example.com",
888+
};
889+
890+
// should bypass proxy (case insensitive match)
891+
assert!(p
892+
.intercept(&"http://example.com".parse().unwrap())
893+
.is_none());
894+
assert!(p
895+
.intercept(&"http://EXAMPLE.COM".parse().unwrap())
896+
.is_none());
897+
assert!(p
898+
.intercept(&"http://Example.com".parse().unwrap())
899+
.is_none());
900+
}
869901
}

0 commit comments

Comments
 (0)