From 836615aac9643bdf5a0368217caf62d7fc88f6a9 Mon Sep 17 00:00:00 2001 From: H1JK Date: Wed, 12 Apr 2023 14:40:38 +0800 Subject: [PATCH] fix: Converter panic on bad VMess share links --- common/buf/sing.go | 16 ++++++++++------ common/convert/converter.go | 15 ++++++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/common/buf/sing.go b/common/buf/sing.go index f86b5755..c176ecb1 100644 --- a/common/buf/sing.go +++ b/common/buf/sing.go @@ -9,10 +9,12 @@ const BufferSize = buf.BufferSize type Buffer = buf.Buffer -var New = buf.New -var StackNew = buf.StackNew -var StackNewSize = buf.StackNewSize -var With = buf.With +var ( + New = buf.New + StackNew = buf.StackNew + StackNewSize = buf.StackNewSize + With = buf.With +) var KeepAlive = common.KeepAlive @@ -21,5 +23,7 @@ func Dup[T any](obj T) T { return common.Dup(obj) } -var Must = common.Must -var Error = common.Error +var ( + Must = common.Must + Error = common.Error +) diff --git a/common/convert/converter.go b/common/convert/converter.go index abd07a94..b67918db 100644 --- a/common/convert/converter.go +++ b/common/convert/converter.go @@ -5,10 +5,11 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/Dreamacro/clash/log" "net/url" "strconv" "strings" + + "github.com/Dreamacro/clash/log" ) // ConvertsV2Ray convert V2Ray subscribe proxies data to clash proxies config @@ -201,7 +202,8 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { vmess["servername"] = sni } - network := strings.ToLower(values["net"].(string)) + network, _ := values["net"].(string) + network = strings.ToLower(network) if values["type"] == "http" { network = "http" } else if network == "http" { @@ -209,9 +211,12 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { } vmess["network"] = network - tls := strings.ToLower(values["tls"].(string)) - if strings.HasSuffix(tls, "tls") { - vmess["tls"] = true + tls, ok := values["tls"].(string) + if ok { + tls = strings.ToLower(tls) + if strings.HasSuffix(tls, "tls") { + vmess["tls"] = true + } } switch network {