From 341ef1909951637e51e4e95689bfc0fd7a0a3e11 Mon Sep 17 00:00:00 2001 From: MetaCubeX Date: Wed, 15 Jun 2022 03:03:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ss/ssr=20URI=20Scheme=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/convert/converter.go | 41 ++++++++++++++----------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/common/convert/converter.go b/common/convert/converter.go index 23fdf652e..662a827ec 100644 --- a/common/convert/converter.go +++ b/common/convert/converter.go @@ -10,34 +10,24 @@ import ( "strings" ) +var encRaw = base64.RawStdEncoding var enc = base64.StdEncoding -func DecodeBase64(buf []byte) ([]byte, error) { - dBuf := make([]byte, enc.DecodedLen(len(buf))) - n, err := enc.Decode(dBuf, buf) +func DecodeBase64(buf []byte) []byte { + dBuf := make([]byte, encRaw.DecodedLen(len(buf))) + n, err := encRaw.Decode(dBuf, buf) if err != nil { - return nil, err + n, err = enc.Decode(dBuf, buf) + if err != nil { + return buf + } } - - return dBuf[:n], nil -} - -// DecodeBase64StringToString decode base64 string to string -func DecodeBase64StringToString(s string) (string, error) { - dBuf, err := enc.DecodeString(s) - if err != nil { - return "", err - } - - return string(dBuf), nil + return dBuf[:n] } // ConvertsV2Ray convert V2Ray subscribe proxies data to clash proxies config func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { - data, err := DecodeBase64(buf) - if err != nil { - data = buf - } + data := DecodeBase64(buf) arr := strings.Split(string(data), "\n") @@ -219,7 +209,7 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { proxies = append(proxies, vless) case "vmess": - dcBuf, err := enc.DecodeString(body) + dcBuf, err := encRaw.DecodeString(body) if err != nil { continue } @@ -323,7 +313,7 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { port := urlSS.Port() if port == "" { - dcBuf, err := enc.DecodeString(urlSS.Host) + dcBuf, err := encRaw.DecodeString(urlSS.Host) if err != nil { continue } @@ -340,11 +330,10 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { ) if password, found = urlSS.User.Password(); !found { - dcBuf, err := enc.DecodeString(cipher) + dcBuf, err := encRaw.DecodeString(cipher) if err != nil { continue } - cipher, password, found = strings.Cut(string(dcBuf), ":") if !found { continue @@ -363,7 +352,7 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { proxies = append(proxies, ss) case "ssr": - dcBuf, err := enc.DecodeString(body) + dcBuf, err := encRaw.DecodeString(body) if err != nil { continue } @@ -435,7 +424,7 @@ func urlSafe(data string) string { } func decodeUrlSafe(data string) string { - dcBuf, err := base64.URLEncoding.DecodeString(data) + dcBuf, err := base64.RawURLEncoding.DecodeString(data) if err != nil { return "" }