1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-23 21:54:42 -05:00

fix: 修复当base64字符串长度不为4的倍数时,解码失败的问题

update: 提高根据ISO匹配国家名称的正确率
This commit is contained in:
Nite07 2023-09-24 14:48:42 +08:00
parent fc21e35465
commit 38352d4cd7
2 changed files with 27 additions and 1 deletions

View File

@ -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

View File

@ -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