diff --git a/proxy/shadowsocksr.go b/proxy/shadowsocksr.go index 66d4b34..cfb4d2b 100644 --- a/proxy/shadowsocksr.go +++ b/proxy/shadowsocksr.go @@ -112,8 +112,11 @@ func ParseSSRLink(link string) (*ShadowsocksR, error) { if err != nil { return nil, ErrorProtocolParamParseFail } - if strings.HasSuffix(protocolParam, "_compatible") { - protocolParam = strings.ReplaceAll(protocolParam, "_compatible", "") + if tool.ContainChineseChar(protocolParam) { + protocolParam = "" + } + if strings.HasSuffix(protocol, "_compatible") { + protocol = strings.ReplaceAll(protocol, "_compatible", "") } // obfs param @@ -121,8 +124,11 @@ func ParseSSRLink(link string) (*ShadowsocksR, error) { if err != nil { return nil, ErrorObfsParamParseFail } - if strings.HasSuffix(obfsParam, "_compatible") { - obfsParam = strings.ReplaceAll(obfsParam, "_compatible", "") + if tool.ContainChineseChar(obfsParam) { + obfsParam = "" + } + if strings.HasSuffix(obfs, "_compatible") { + obfs = strings.ReplaceAll(obfs, "_compatible", "") } //group, err := tool.Base64DecodeString(moreInfo.Get("group")) diff --git a/tool/unicode.go b/tool/unicode.go new file mode 100644 index 0000000..d9f946f --- /dev/null +++ b/tool/unicode.go @@ -0,0 +1,17 @@ +package tool + +import ( + "regexp" + "unicode" +) + +var hanRe = regexp.MustCompile("[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]") + +func ContainChineseChar(str string) bool { + for _, r := range str { + if unicode.Is(unicode.Scripts["Han"], r) || (hanRe.MatchString(string(r))) { + return true + } + } + return false +}