Skip to content

Commit b0ee624

Browse files
committed
feat: Make domain matcher case-insensitive
1 parent b424f99 commit b0ee624

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

common/domain/matcher.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package domain
22

33
import (
44
"sort"
5+
"strings"
56
"unicode/utf8"
67
)
78

@@ -13,6 +14,7 @@ func NewMatcher(domains []string, domainSuffix []string) *Matcher {
1314
domainList := make([]string, 0, len(domains)+2*len(domainSuffix))
1415
seen := make(map[string]bool, len(domainList))
1516
for _, domain := range domainSuffix {
17+
domain = strings.ToLower(domain)
1618
if seen[domain] {
1719
continue
1820
}
@@ -24,6 +26,7 @@ func NewMatcher(domains []string, domainSuffix []string) *Matcher {
2426
}
2527
}
2628
for _, domain := range domains {
29+
domain = strings.ToLower(domain)
2730
if seen[domain] {
2831
continue
2932
}
@@ -35,7 +38,7 @@ func NewMatcher(domains []string, domainSuffix []string) *Matcher {
3538
}
3639

3740
func (m *Matcher) Match(domain string) bool {
38-
return m.set.Has(reverseDomain(domain))
41+
return m.set.Has(reverseDomain(strings.ToLower(domain)))
3942
}
4043

4144
func reverseDomain(domain string) string {

common/domain/matcher_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import "testing"
55
func TestMatcher(t *testing.T) {
66
matcher := NewMatcher(
77
[]string{ // domain
8-
"example.com", "example.com.", "example.org",
8+
"eXample.com", "example.com.", "example.org",
99
}, []string{ // domain suffix
10-
"example.net", ".example.invalid",
10+
"example.net", ".exampLe.invalid",
1111
})
12-
if !matcher.Match("example.com") {
12+
if !matcher.Match("exaMple.com") {
1313
t.Error("example.com is not matched")
1414
}
1515
if !matcher.Match("example.com.") {
@@ -30,7 +30,7 @@ func TestMatcher(t *testing.T) {
3030
if !matcher.Match("any.one.example.net") {
3131
t.Error("any.one.one.example.net is not matched")
3232
}
33-
if matcher.Match("example.invalid") {
33+
if matcher.Match("example.invAlid") {
3434
t.Error("example.invalid is matched")
3535
}
3636
if !matcher.Match("any.example.invalid") {

0 commit comments

Comments
 (0)