From a20b9a3960658fb2844e5c52200705f1fc5cb90e Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Sun, 29 Aug 2021 22:19:22 +0800 Subject: [PATCH] Chore: make geoip match case-insensitive (#1574) --- dns/filters.go | 3 ++- rule/geoip.go | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dns/filters.go b/dns/filters.go index c9cece05..bacd7727 100644 --- a/dns/filters.go +++ b/dns/filters.go @@ -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 { diff --git a/rule/geoip.go b/rule/geoip.go index 0b94c4c2..3b6fbe6b 100644 --- a/rule/geoip.go +++ b/rule/geoip.go @@ -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 {