From 9e50b30af6590609cb156c449756deea83e8d24d Mon Sep 17 00:00:00 2001 From: Lael Date: Wed, 10 Jul 2024 11:33:43 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8Dss=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E6=97=B6ipv6=E5=9C=B0=E5=9D=80=E8=A7=A3=E6=9E=90=E9=94=99?= =?UTF-8?q?=E8=AF=AF=20(#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parser/shadowsocks.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/parser/shadowsocks.go b/parser/shadowsocks.go index f81d34b..c7f4092 100644 --- a/parser/shadowsocks.go +++ b/parser/shadowsocks.go @@ -23,7 +23,6 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) { } } - var serverAndPort []string if !strings.Contains(urlParts[0], ":") { decoded, err := util.DecodeBase64(urlParts[0]) if err != nil { @@ -45,16 +44,21 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) { } method, password := credentials[0], credentials[1] - serverInfo := strings.SplitN(urlParts[1], "#", 2) - serverAndPort = strings.SplitN(serverInfo[0], ":", 2) - server, portStr := serverAndPort[0], serverAndPort[1] - if len(serverInfo) != 2 { + serverInfoAndTag := strings.SplitN(urlParts[1], "#", 2) + serverAndPort := serverInfoAndTag[0] + + lastColonIndex := strings.LastIndex(serverAndPort, ":") + if lastColonIndex == -1 { return model.Outbound{}, &ParseError{ Type: ErrInvalidStruct, - Message: "missing server host or port", + Message: "missing port in address", Raw: proxy, } } + + server := serverAndPort[:lastColonIndex] + portStr := serverAndPort[lastColonIndex+1:] + port, err := ParsePort(portStr) if err != nil { return model.Outbound{}, &ParseError{ @@ -65,8 +69,8 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) { } var remarks string - if len(serverInfo) == 2 { - unescape, err := url.QueryUnescape(serverInfo[1]) + if len(serverInfoAndTag) == 2 { + unescape, err := url.QueryUnescape(serverInfoAndTag[1]) if err != nil { return model.Outbound{}, &ParseError{ Type: ErrInvalidStruct,