Skip to content

Commit ff38392

Browse files
fix: unandled error while parsing URL (#160)
* fix: unandled error while parsing URL * adds test
1 parent dba47a7 commit ff38392

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.3.2
1+
v0.4.1

proxy/service.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ func NewService(name string, rawURL string) (Service, error) {
2424
}
2525

2626
url, err := url.ParseRequestURI(rawURL)
27+
if err != nil {
28+
return Service{}, fmt.Errorf("Error parsing URL '%v': %v", rawURL, err)
29+
}
30+
2731
isInvalidHostname := len(url.Hostname()) == 0 || strings.Contains(url.Hostname(), ":")
28-
if err != nil || isInvalidHostname {
32+
if isInvalidHostname {
2933
return Service{}, fmt.Errorf("URL '%v' is invalid, example of valid URL 'http://example.com:8080'", rawURL)
3034
}
3135

proxy/service_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ func TestNewService(t *testing.T) {
5454
serviceURL: "http://localhost:8080",
5555
expectError: true,
5656
},
57+
{
58+
title: "a service containing an invalid URL is invalid",
59+
serviceName: "ergoproxy",
60+
serviceURL: "http:///localhost:3000\n",
61+
expectError: true,
62+
},
5763
}
5864

5965
for _, tc := range testCases {

0 commit comments

Comments
 (0)