diff --git a/internal/utils/validator.go b/internal/utils/validator.go index 752f3d87..d48ea0cd 100644 --- a/internal/utils/validator.go +++ b/internal/utils/validator.go @@ -1,11 +1,26 @@ package utils -import "github.com/asaskevich/govalidator" +import ( + "net/url" + + "github.com/asaskevich/govalidator" +) func ValidateEmail(email string) bool { return govalidator.IsEmail(email) } -func ValidateURL(url string) bool { - return govalidator.IsRequestURL(url) +func ValidateURL(v string) bool { + u, err := url.ParseRequestURI(v) + if err != nil { + return false + } + if len(u.Scheme) == 0 { + return false + } + // Must https or http + if u.Scheme != "https" && u.Scheme != "http" { + return false + } + return true } diff --git a/internal/utils/validator_test.go b/internal/utils/validator_test.go index 30ad1ff6..7bc6dad6 100644 --- a/internal/utils/validator_test.go +++ b/internal/utils/validator_test.go @@ -29,7 +29,8 @@ func TestValidateURL(t *testing.T) { }{ {"https://example.com", true}, {"invalid.url", false}, - {"https://example.com/path?param=value", true}, + {"http://example.com/path?param=value", true}, + {"ftp://example.com", false}, } for _, tc := range testCases {