File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package domain
22
33import (
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
3740func (m * Matcher ) Match (domain string ) bool {
38- return m .set .Has (reverseDomain (domain ))
41+ return m .set .Has (reverseDomain (strings . ToLower ( domain ) ))
3942}
4043
4144func reverseDomain (domain string ) string {
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ import "testing"
55func 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" ) {
You can’t perform that action at this time.
0 commit comments