From 774966f2eb1a5975165b926b5172834fc6d1c642 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 29 Jun 2023 22:05:32 +0800 Subject: [PATCH] chore: validate shortcut name --- api/v1/shortcut.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/v1/shortcut.go b/api/v1/shortcut.go index 0194d62..dcc114a 100644 --- a/api/v1/shortcut.go +++ b/api/v1/shortcut.go @@ -92,7 +92,7 @@ func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) { shortcut, err := s.Store.CreateShortcut(ctx, &store.Shortcut{ CreatorID: userID, - Name: create.Name, + Name: strings.ToLower(create.Name), Link: create.Link, Description: create.Description, Visibility: convertVisibilityToStore(create.Visibility), @@ -147,6 +147,10 @@ func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) { if err := json.NewDecoder(c.Request().Body).Decode(patch); err != nil { return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch shortcut request").SetInternal(err) } + if patch.Name != nil { + name := strings.ToLower(*patch.Name) + patch.Name = &name + } if patch.Link != nil && !validateLink(*patch.Link) { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid link: %s", *patch.Link)) }