Skip to content

Commit

Permalink
fix: comment author url validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jakezhu9 committed May 13, 2023
1 parent a307277 commit 7d1e2d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion handler/content/api/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,13 @@ func (j *JournalHandler) CreateComment(ctx *gin.Context) (interface{}, error) {
p := param.Comment{}
err := ctx.ShouldBindJSON(&p)
if err != nil {
return nil, err
return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("Parameter error")
}
if p.AuthorURL != "" {
err = util.Validate.Var(p.AuthorURL, "http_url")
if err != nil {
return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("Parameter error")
}
}
p.Author = template.HTMLEscapeString(p.Author)
p.AuthorURL = template.HTMLEscapeString(p.AuthorURL)
Expand Down
8 changes: 7 additions & 1 deletion handler/content/api/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ func (p *PostHandler) CreateComment(ctx *gin.Context) (interface{}, error) {
comment := param.Comment{}
err := ctx.ShouldBindJSON(&comment)
if err != nil {
return nil, err
return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("Parameter error")
}
if comment.AuthorURL != "" {
err = util.Validate.Var(comment.AuthorURL, "http_url")
if err != nil {
return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("Parameter error")
}
}
comment.Author = template.HTMLEscapeString(comment.Author)
comment.AuthorURL = template.HTMLEscapeString(comment.AuthorURL)
Expand Down
8 changes: 7 additions & 1 deletion handler/content/api/sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ func (s *SheetHandler) CreateComment(ctx *gin.Context) (interface{}, error) {
comment := param.Comment{}
err := ctx.ShouldBindJSON(&comment)
if err != nil {
return nil, err
return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("Parameter error")
}
if comment.AuthorURL != "" {
err = util.Validate.Var(comment.AuthorURL, "http_url")
if err != nil {
return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("Parameter error")
}
}
comment.Author = template.HTMLEscapeString(comment.Author)
comment.AuthorURL = template.HTMLEscapeString(comment.AuthorURL)
Expand Down

0 comments on commit 7d1e2d8

Please sign in to comment.