From 3e760d2848632d3b05f1ae92d8f24d3d7493a1e9 Mon Sep 17 00:00:00 2001 From: Stephanie Gredell Date: Mon, 18 Nov 2024 03:40:45 -0500 Subject: [PATCH] Add simple url validation --- pages/goals.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pages/goals.go b/pages/goals.go index c4a18af..8098b76 100644 --- a/pages/goals.go +++ b/pages/goals.go @@ -5,6 +5,7 @@ import ( "github.com/gin-gonic/gin" "log" "net/http" + "net/url" "sponsorahacker/db" "sponsorahacker/utils" "strconv" @@ -45,7 +46,9 @@ func CreateGoal(c *gin.Context) { description := strings.TrimSpace(c.PostForm("item-description")) learnMoreURL := strings.TrimSpace(c.PostForm("item-url")) - if name == "" && fundingAmountStr == "" && description == "" && learnMoreURL == "" { + _, validateErr := url.Parse(learnMoreURL) + + if name == "" && fundingAmountStr == "" && description == "" && learnMoreURL == "" && validateErr != nil { fieldError := fmt.Errorf("missing a required field. Please check and make sure all fields are filled out") c.HTML(http.StatusOK, "goals.html", gin.H{ "title": "Sponsor A Hacker",