mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-06-17 04:33:18 +08:00
Refactor Shadowsocks and Socks parsers to simplify username and password extraction
This commit is contained in:
@ -99,22 +99,8 @@ func (p *ShadowsocksParser) Parse(proxy string) (P.Proxy, error) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
methodAndPass := strings.SplitN(decodedStr, ":", 2)
|
methodAndPass := strings.SplitN(decodedStr, ":", 2)
|
||||||
if len(methodAndPass) == 2 {
|
if len(methodAndPass) == 2 {
|
||||||
method, err = url.QueryUnescape(methodAndPass[0])
|
method = methodAndPass[0]
|
||||||
if err != nil {
|
password = methodAndPass[1]
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
method = decodedStr
|
method = decodedStr
|
||||||
}
|
}
|
||||||
|
@ -78,31 +78,10 @@ func (p *SocksParser) Parse(proxy string) (P.Proxy, error) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
usernameAndPassword := strings.SplitN(decodedStr, ":", 2)
|
usernameAndPassword := strings.SplitN(decodedStr, ":", 2)
|
||||||
if len(usernameAndPassword) == 2 {
|
if len(usernameAndPassword) == 2 {
|
||||||
username, err = url.QueryUnescape(usernameAndPassword[0])
|
username = usernameAndPassword[0]
|
||||||
if err != nil {
|
password = usernameAndPassword[1]
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
username, err = url.QueryUnescape(decodedStr)
|
username = decodedStr
|
||||||
if err != nil {
|
|
||||||
return P.Proxy{}, &ParseError{
|
|
||||||
Type: ErrInvalidStruct,
|
|
||||||
Message: "invalid username",
|
|
||||||
Raw: proxy,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user