Compare commits

...

1 Commits

Author SHA1 Message Date
刘祥超
c024049778 优化域名匹配,现在 example.com:* 可以匹配 example.com 2023-01-10 10:03:43 +08:00
2 changed files with 9 additions and 1 deletions

View File

@@ -64,7 +64,7 @@ func MatchDomain(pattern string, domain string) (isMatched bool) {
var portIndex = strings.LastIndex(patternPiece, ":*")
if portIndex >= 0 {
var prefix = patternPiece[:portIndex]
if strings.HasPrefix(domainPieces[index], prefix+":") {
if strings.HasPrefix(domainPieces[index], prefix+":") || domainPieces[index] == prefix {
continue
}
}

View File

@@ -94,6 +94,14 @@ func TestMatchDomain(t *testing.T) {
var ok = MatchDomains([]string{"*.example.com:8001"}, "a.example.com:8001")
a.IsTrue(ok)
}
{
var ok = MatchDomains([]string{"a.example.com:*"}, "a.example.com:8001")
a.IsTrue(ok)
}
{
var ok = MatchDomains([]string{"a.example.com:*"}, "a.example.com")
a.IsTrue(ok)
}
{
var ok = MatchDomains([]string{"*.example.com:*"}, "a.example.com:8001")
a.IsTrue(ok)