Skip to content

Commit

Permalink
Fix an issue where undefined proxy in autoconfig could cause a panic … (
Browse files Browse the repository at this point in the history
#26)

* Fix an issue where undefined proxy in autoconfig could cause a panic and prevent winhttp proxy from being checked

* remove unneeded debug logs
  • Loading branch information
bli-r7 authored Nov 24, 2021
1 parent 5dbdee5 commit e4a594c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
9 changes: 8 additions & 1 deletion proxy/provider_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,18 @@ Returns:
//noinspection SpellCheckingInspection
func (p *providerWindows) parseLpszProxy(protocol string, lpszProxy string) []string {
proxies := []string{}
lpszProxy = strings.TrimSpace(lpszProxy)
if len(lpszProxy) == 0 {
return proxies
}
for _, s := range strings.Split(lpszProxy, ";") {
parts := strings.SplitN(s, "=", 2)
// Include the proxy if protocol matches or if no protocol is specified
if len(parts) < 2 || strings.TrimSpace(parts[0]) == protocol {
if len(parts) < 2 {
// Assign a match, but keep looking in case we have a protocol specific match
proxies = append(proxies, s)
} else if strings.TrimSpace(parts[0]) == protocol {
proxies = append(proxies, parts[1])
}
}
return proxies
Expand Down
14 changes: 7 additions & 7 deletions proxy/provider_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (

var dataProviderWindowsParseLpszProxy = []struct {
lpszProxy string
expect string
expect []string
}{
{"1.2.3.4:8443", "1.2.3.4:8443"},
{"1.2.3.4:8443;4.5.6.7:8999", "4.5.6.7:8999"},
{"1.2.3.4:8443;http=4.5.6.7:8999", "1.2.3.4:8443"},
{"http=1.2.3.4:8443;https=4.5.6.7:8999", "4.5.6.7:8999"},
{"", ""},
{" ", " "},
{"1.2.3.4:8443", []string{"1.2.3.4:8443"}},
{"1.2.3.4:8443;4.5.6.7:8999", []string{"1.2.3.4:8443","4.5.6.7:8999"}},
{"1.2.3.4:8443;http=4.5.6.7:8999", []string{"1.2.3.4:8443"}},
{"http=1.2.3.4:8443;https=4.5.6.7:8999", []string{"4.5.6.7:8999"}},
{"", []string{}},
{" ", []string{}},
}

func TestProviderWindows_ParseLpszProxy(t *testing.T) {
Expand Down

0 comments on commit e4a594c

Please sign in to comment.