From 38352d4cd72b07099a883ec42aa40376251ee4cd Mon Sep 17 00:00:00 2001 From: nitezs Date: Sun, 24 Sep 2023 14:48:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BD=93base64?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E9=95=BF=E5=BA=A6=E4=B8=8D=E4=B8=BA?= =?UTF-8?q?4=E7=9A=84=E5=80=8D=E6=95=B0=E6=97=B6=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E7=A0=81=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=20update?= =?UTF-8?q?:=20=E6=8F=90=E9=AB=98=E6=A0=B9=E6=8D=AEISO=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=9B=BD=E5=AE=B6=E5=90=8D=E7=A7=B0=E7=9A=84=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parser/base64.go | 5 +++++ utils/proxy.go | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/parser/base64.go b/parser/base64.go index 4909d04..b14d423 100644 --- a/parser/base64.go +++ b/parser/base64.go @@ -2,9 +2,14 @@ package parser import ( "encoding/base64" + "strings" ) func DecodeBase64(s string) (string, error) { + s = strings.TrimSpace(s) + if len(s)%4 != 0 { + s += strings.Repeat("=", 4-len(s)%4) + } decodeStr, err := base64.StdEncoding.DecodeString(s) if err != nil { return "", err diff --git a/utils/proxy.go b/utils/proxy.go index 7868791..6822600 100644 --- a/utils/proxy.go +++ b/utils/proxy.go @@ -16,7 +16,28 @@ func GetContryName(proxy model.Proxy) string { } // 对每一个映射进行检查 - for _, countryMap := range countryMaps { + for i, countryMap := range countryMaps { + if i == 2 { + // 对ISO匹配做特殊处理 + // 根据常用分割字符分割字符串 + splitChars := []string{"-", "_", " "} + key := make([]string, 0) + for _, splitChar := range splitChars { + slic := strings.Split(proxy.Name, splitChar) + for _, v := range slic { + if len(v) == 2 { + key = append(key, v) + } + } + } + // 对每一个分割后的字符串进行检查 + for _, v := range key { + // 如果匹配到了国家 + if country, ok := countryMap[strings.ToUpper(v)]; ok { + return country + } + } + } for k, v := range countryMap { if strings.Contains(proxy.Name, k) { return v