mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-30 01:00:27 +08:00
优化域名匹配,现在 example.com:* 可以匹配 example.com
This commit is contained in:
@@ -64,7 +64,7 @@ func MatchDomain(pattern string, domain string) (isMatched bool) {
|
|||||||
var portIndex = strings.LastIndex(patternPiece, ":*")
|
var portIndex = strings.LastIndex(patternPiece, ":*")
|
||||||
if portIndex >= 0 {
|
if portIndex >= 0 {
|
||||||
var prefix = patternPiece[:portIndex]
|
var prefix = patternPiece[:portIndex]
|
||||||
if strings.HasPrefix(domainPieces[index], prefix+":") {
|
if strings.HasPrefix(domainPieces[index], prefix+":") || domainPieces[index] == prefix {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,14 @@ func TestMatchDomain(t *testing.T) {
|
|||||||
var ok = MatchDomains([]string{"*.example.com:8001"}, "a.example.com:8001")
|
var ok = MatchDomains([]string{"*.example.com:8001"}, "a.example.com:8001")
|
||||||
a.IsTrue(ok)
|
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")
|
var ok = MatchDomains([]string{"*.example.com:*"}, "a.example.com:8001")
|
||||||
a.IsTrue(ok)
|
a.IsTrue(ok)
|
||||||
|
|||||||
Reference in New Issue
Block a user