Skip to content

Commit

Permalink
Support ipv6 proxy address
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Aug 14, 2023
1 parent abd1cc8 commit 32c9598
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions cmd/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ var (
// nolint
matchNoneRegex = regexp.MustCompile("a^")
// nolint
ntlmProxyRegex = regexp.MustCompile(`^.*\\.+$`)
// nolint
pluginRegex = regexp.MustCompile(`(?i)([a-z\/0-9.]+\s)?(?P<editor>[a-z-]+)\-wakatime\/[0-9.]+`)
// nolint
proxyRegex = regexp.MustCompile(`^((https?|socks5)://)?([^:@]+(:([^:@])+)?@)?[^:]+(:\d+)?$`)
proxyIPv6Regex = regexp.MustCompile(`^((https?|socks5)://)?([^:@]+(:([^:@])+)?@)?(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(:\d+)?$`)
// nolint
ntlmProxyRegex = regexp.MustCompile(`^.*\\.+$`)
proxyRegex = regexp.MustCompile(`^((https?|socks5)://)?([^:@]+(:([^:@])+)?@)?[^:]+(:\d+)?$`)
)

type (
Expand Down Expand Up @@ -273,7 +275,9 @@ func LoadAPIParams(v *viper.Viper) (API, error) {
}

if proxyURL != "" && !rgx.MatchString(proxyURL) {
return API{}, api.ErrAuth{Err: fmt.Errorf(errMsgTemplate, proxyURL)}
if !proxyIPv6Regex.MatchString(proxyURL) {
return API{}, api.ErrAuth{Err: fmt.Errorf(errMsgTemplate, proxyURL)}
}
}

proxyEnv := httpproxy.FromEnvironment()
Expand Down
3 changes: 2 additions & 1 deletion cmd/params/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2011,8 +2011,9 @@ func TestLoad_API_ProxyURL(t *testing.T) {
tests := map[string]string{
"https": "https://john:[email protected]:8888",
"http": "http://john:[email protected]:8888",
"socks5": "socks5://john:secret@example.org:8888",
"ipv6": "socks5://john:secret@2001:0db8:85a3:0000:0000:8a2e:0370:7334:8888",
"ntlm": `domain\\john:123456`,
"socks5": "socks5://john:[email protected]:8888",
}

for name, proxyURL := range tests {
Expand Down

0 comments on commit 32c9598

Please sign in to comment.