From 95b5ae44900a02db39315779731d6222630a4403 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sun, 7 Aug 2022 20:43:11 +0800 Subject: [PATCH] fix: Converter error when VMess `aid` field not exists --- common/convert/converter.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/common/convert/converter.go b/common/convert/converter.go index 4c1aceb5..811acecb 100644 --- a/common/convert/converter.go +++ b/common/convert/converter.go @@ -10,8 +10,10 @@ import ( "strings" ) -var encRaw = base64.RawStdEncoding -var enc = base64.StdEncoding +var ( + encRaw = base64.RawStdEncoding + enc = base64.StdEncoding +) func DecodeBase64(buf []byte) []byte { dBuf := make([]byte, encRaw.DecodedLen(len(buf))) @@ -149,7 +151,7 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { vless["skip-cert-verify"] = false vless["tls"] = false tls := strings.ToLower(query.Get("security")) - if strings.Contains(tls, "tls") { + if strings.HasSuffix(tls, "tls") { vless["tls"] = true } sni := query.Get("sni") @@ -244,7 +246,11 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { vmess["server"] = values["add"] vmess["port"] = values["port"] vmess["uuid"] = values["id"] - vmess["alterId"] = values["aid"] + if alterId, ok := values["aid"]; ok { + vmess["alterId"] = alterId + } else { + vmess["alterId"] = 0 + } vmess["cipher"] = "auto" vmess["udp"] = true vmess["tls"] = false