Skip to content

Commit

Permalink
Improve parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
yunginnanet committed Oct 12, 2022
1 parent 60484db commit aae6c2e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ func filter(in string) (filtered string, ok bool) { //nolint:cyclop
return "", false
}
return combo.String(), true
case 3:
if !strings.Contains(in, "@") {
return "", false
}
split := strings.Split(in, "@")
if !strings.Contains(split[0], ":") {
return "", false
}
splitAuth := strings.Split(split[0], ":")
splitServ := strings.Split(split[1], ":")
_, isDomain := dns.IsDomainName(splitServ[0])
if isDomain && isNumber(splitServ[1]) {
return buildProxyString(splitAuth[0], splitAuth[1],
splitServ[0], splitServ[1], false), true
}
if _, err := ipa.ParseIPPort(split[1]); err == nil {
return buildProxyString(splitAuth[0], splitAuth[1],
splitServ[0], splitServ[1], false), true
}
case 4:
_, isDomain := dns.IsDomainName(split[0])
if isDomain && isNumber(split[1]) {
Expand Down
8 changes: 8 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func Test_filter(t *testing.T) {
wantFiltered: "user:[email protected]:1080",
wantOk: true,
},
{
name: "withAuthAlt",
args: args{
in: "user:[email protected]:1080",
},
wantFiltered: "user:[email protected]:1080",
wantOk: true,
},
{
name: "simpleDomain",
args: args{
Expand Down

0 comments on commit aae6c2e

Please sign in to comment.