-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(validator): restrict to allow only HTTP protocol
- Loading branch information
Showing
2 changed files
with
20 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters