From bed4a3f916127f80137dbbf34b08384877361540 Mon Sep 17 00:00:00 2001 From: CaIon Date: Sat, 4 Jul 2026 16:56:37 +0800 Subject: [PATCH] fix(user): trim whitespace from username and validate input --- controller/user.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/controller/user.go b/controller/user.go index 0e3dc89c..596f8ff8 100644 --- a/controller/user.go +++ b/controller/user.go @@ -190,6 +190,11 @@ func Register(c *gin.Context) { common.ApiErrorI18n(c, i18n.MsgInvalidParams) return } + user.Username = strings.TrimSpace(user.Username) + if user.Username == "" { + common.ApiErrorI18n(c, i18n.MsgInvalidParams) + return + } if err := common.Validate.Struct(&user); err != nil { common.ApiErrorI18n(c, i18n.MsgUserInputInvalid, map[string]any{"Error": err.Error()}) return @@ -631,6 +636,11 @@ func UpdateUser(c *gin.Context) { common.ApiErrorI18n(c, i18n.MsgInvalidParams) return } + updatedUser.Username = strings.TrimSpace(updatedUser.Username) + if updatedUser.Username == "" { + common.ApiErrorI18n(c, i18n.MsgInvalidParams) + return + } if updatedUser.Password == "" { updatedUser.Password = "$I_LOVE_U" // make Validator happy :) }