Refactor Shadowsocks and Socks parsers to simplify username and password extraction

This commit is contained in:
2025-06-12 15:48:59 +10:00
parent 6a780a5e27
commit 69deed91df
2 changed files with 5 additions and 40 deletions

View File

@ -99,22 +99,8 @@ func (p *ShadowsocksParser) Parse(proxy string) (P.Proxy, error) {
if err == nil {
methodAndPass := strings.SplitN(decodedStr, ":", 2)
if len(methodAndPass) == 2 {
method, err = url.QueryUnescape(methodAndPass[0])
if err != nil {
return P.Proxy{}, &ParseError{
Type: ErrInvalidStruct,
Message: "invalid method",
Raw: proxy,
}
}
password, err = url.QueryUnescape(methodAndPass[1])
if err != nil {
return P.Proxy{}, &ParseError{
Type: ErrInvalidStruct,
Message: "invalid password",
Raw: proxy,
}
}
method = methodAndPass[0]
password = methodAndPass[1]
} else {
method = decodedStr
}

View File

@ -78,31 +78,10 @@ func (p *SocksParser) Parse(proxy string) (P.Proxy, error) {
if err == nil {
usernameAndPassword := strings.SplitN(decodedStr, ":", 2)
if len(usernameAndPassword) == 2 {
username, err = url.QueryUnescape(usernameAndPassword[0])
if err != nil {
return P.Proxy{}, &ParseError{
Type: ErrInvalidStruct,
Message: "invalid username",
Raw: proxy,
}
}
password, err = url.QueryUnescape(usernameAndPassword[1])
if err != nil {
return P.Proxy{}, &ParseError{
Type: ErrInvalidStruct,
Message: "invalid password",
Raw: proxy,
}
}
username = usernameAndPassword[0]
password = usernameAndPassword[1]
} else {
username, err = url.QueryUnescape(decodedStr)
if err != nil {
return P.Proxy{}, &ParseError{
Type: ErrInvalidStruct,
Message: "invalid username",
Raw: proxy,
}
}
username = decodedStr
}
}
}