Skip to content

Commit dd4eb1f

Browse files
authored
Merge pull request #20 from gummiboll/case-insensitive
Case insensitive url validation
2 parents 52117da + 258944b commit dd4eb1f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

url.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import (
55
"fmt"
66
"io"
77
"net/http"
8-
"strings"
8+
"regexp"
99
"time"
1010
)
1111

1212
func validURL(url string) bool {
13-
return strings.HasPrefix(url, "https://") || strings.HasPrefix(url, "http://")
13+
r := regexp.MustCompile("(?i)^http(?:s)?://")
14+
return r.MatchString(url)
1415
}
1516

1617
func getURL(url string) (io.Reader, error) {

url_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ func TestValidURL(t *testing.T) {
1111
}{
1212
{"http://test.com", true},
1313
{"https://test.com", true},
14+
{"HttPs://test.com", true},
1415
{"/test/test.com", false},
1516
{"", false},
1617
}

0 commit comments

Comments
 (0)