Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unandled error while parsing URL #160

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.3.2
v0.4.1
6 changes: 5 additions & 1 deletion proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ func NewService(name string, rawURL string) (Service, error) {
}

url, err := url.ParseRequestURI(rawURL)
if err != nil {
return Service{}, fmt.Errorf("Error parsing URL '%v': %v", rawURL, err)
}

isInvalidHostname := len(url.Hostname()) == 0 || strings.Contains(url.Hostname(), ":")
if err != nil || isInvalidHostname {
if isInvalidHostname {
return Service{}, fmt.Errorf("URL '%v' is invalid, example of valid URL 'http://example.com:8080'", rawURL)
}

Expand Down
6 changes: 6 additions & 0 deletions proxy/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func TestNewService(t *testing.T) {
serviceURL: "http://localhost:8080",
expectError: true,
},
{
title: "a service containing an invalid URL is invalid",
serviceName: "ergoproxy",
serviceURL: "http:///localhost:3000\n",
expectError: true,
},
}

for _, tc := range testCases {
Expand Down
Loading