Skip to content

Commit

Permalink
fix: unandled error while parsing URL (#160)
Browse files Browse the repository at this point in the history
* fix: unandled error while parsing URL

* adds test
  • Loading branch information
cristianoliveira authored Jun 12, 2024
1 parent dba47a7 commit ff38392
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
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

0 comments on commit ff38392

Please sign in to comment.