From aa0753ac597ed4dcf68ee0ab12ed53e51a19c5d8 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sun, 15 May 2022 23:07:06 +0800 Subject: [PATCH] fix: geoip ReverseMatch --- component/geodata/utils.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/component/geodata/utils.go b/component/geodata/utils.go index 840e54d0..facc72e1 100644 --- a/component/geodata/utils.go +++ b/component/geodata/utils.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/Dreamacro/clash/component/geodata/router" C "github.com/Dreamacro/clash/constant" - "strings" ) var geoLoaderName = "memconservative" @@ -70,12 +69,21 @@ func LoadGeoSiteMatcher(countryCode string) (*router.DomainMatcher, int, error) } func LoadGeoIPMatcher(country string) (*router.GeoIPMatcher, int, error) { + if len(country) == 0 { + return nil, 0, fmt.Errorf("country code could not be empty") + } geoLoader, err := GetGeoDataLoader(geoLoaderName) if err != nil { return nil, 0, err } - records, err := geoLoader.LoadGeoIP(strings.ReplaceAll(country, "!", "")) + not := false + if country[0] == '!' { + not = true + country = country[1:] + } + + records, err := geoLoader.LoadGeoIP(country) if err != nil { return nil, 0, err } @@ -83,7 +91,7 @@ func LoadGeoIPMatcher(country string) (*router.GeoIPMatcher, int, error) { geoIP := &router.GeoIP{ CountryCode: country, Cidr: records, - ReverseMatch: strings.Contains(country, "!"), + ReverseMatch: not, } matcher, err := router.NewGeoIPMatcher(geoIP)