Chore: make geoip match case-insensitive (#1574)

This commit is contained in:
Loyalsoldier 2021-08-29 22:19:22 +08:00 committed by GitHub
parent e0d3f926b7
commit a20b9a3960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package dns
import (
"net"
"strings"
"github.com/Dreamacro/clash/component/mmdb"
"github.com/Dreamacro/clash/component/trie"
@ -17,7 +18,7 @@ type geoipFilter struct {
func (gf *geoipFilter) Match(ip net.IP) bool {
record, _ := mmdb.Instance().Country(ip)
return record.Country.IsoCode != gf.code && !ip.IsPrivate()
return !strings.EqualFold(record.Country.IsoCode, gf.code) && !ip.IsPrivate()
}
type ipnetFilter struct {

View File

@ -1,6 +1,8 @@
package rules
import (
"strings"
"github.com/Dreamacro/clash/component/mmdb"
C "github.com/Dreamacro/clash/constant"
)
@ -21,11 +23,11 @@ func (g *GEOIP) Match(metadata *C.Metadata) bool {
return false
}
if g.country == "LAN" {
if strings.EqualFold(g.country, "LAN") {
return ip.IsPrivate()
}
record, _ := mmdb.Instance().Country(ip)
return record.Country.IsoCode == g.country
return strings.EqualFold(record.Country.IsoCode, g.country)
}
func (g *GEOIP) Adapter() string {