mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-06 04:42:36 +02:00
Add Regex matching
This commit is contained in:
parent
758be58b31
commit
df5b3fdda8
3 changed files with 29 additions and 2 deletions
|
@ -3,6 +3,7 @@ package api
|
|||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
|
@ -87,6 +88,19 @@ func (rt *_router) PostComment(w http.ResponseWriter, r *http.Request, ps httpro
|
|||
return
|
||||
}
|
||||
|
||||
// check if the comment is valid (should not contain newlines and at be between 5 and 255 characters)
|
||||
stat, err := regexp.Match(`^[*]{5, 255}$`, []byte(request_body.Comment))
|
||||
|
||||
if err != nil {
|
||||
helpers.SendInternalError(err, "Error matching regex", w, rt.baseLogger)
|
||||
return
|
||||
}
|
||||
|
||||
if !stat {
|
||||
helpers.SendBadRequest(w, "Invalid comment", rt.baseLogger)
|
||||
return
|
||||
}
|
||||
|
||||
// add the comment to the database
|
||||
success, err := rt.db.PostComment(uid, photo_id, request_body.UID, request_body.Comment)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue