mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-18 21:19:44 +00:00
chore: validate shortcut name
This commit is contained in:
parent
1792ca1272
commit
774966f2eb
@ -92,7 +92,7 @@ func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) {
|
|||||||
|
|
||||||
shortcut, err := s.Store.CreateShortcut(ctx, &store.Shortcut{
|
shortcut, err := s.Store.CreateShortcut(ctx, &store.Shortcut{
|
||||||
CreatorID: userID,
|
CreatorID: userID,
|
||||||
Name: create.Name,
|
Name: strings.ToLower(create.Name),
|
||||||
Link: create.Link,
|
Link: create.Link,
|
||||||
Description: create.Description,
|
Description: create.Description,
|
||||||
Visibility: convertVisibilityToStore(create.Visibility),
|
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 {
|
if err := json.NewDecoder(c.Request().Body).Decode(patch); err != nil {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch shortcut request").SetInternal(err)
|
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) {
|
if patch.Link != nil && !validateLink(*patch.Link) {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid link: %s", *patch.Link))
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid link: %s", *patch.Link))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user