diff --git a/app/http/endpoints/api/forms/createform.go b/app/http/endpoints/api/forms/createform.go index 5f7bfca..f725146 100644 --- a/app/http/endpoints/api/forms/createform.go +++ b/app/http/endpoints/api/forms/createform.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "strings" + "unicode/utf8" "github.com/TicketsBot-cloud/dashboard/app" "github.com/TicketsBot-cloud/dashboard/app/http/audit" @@ -33,8 +34,8 @@ func CreateForm(c *gin.Context) { return } - if len(data.Title) > 45 { - c.JSON(400, utils.ErrorStr("Form title must be 45 characters or less (current: %d characters)", len(data.Title))) + if utf8.RuneCountInString(data.Title) > 45 { + c.JSON(400, utils.ErrorStr("Form title must be 45 characters or less (current: %d characters)", utf8.RuneCountInString(data.Title))) return } diff --git a/app/http/endpoints/api/forms/updateform.go b/app/http/endpoints/api/forms/updateform.go index 9547e6d..29dfce5 100644 --- a/app/http/endpoints/api/forms/updateform.go +++ b/app/http/endpoints/api/forms/updateform.go @@ -4,6 +4,7 @@ import ( "net/http" "strconv" "strings" + "unicode/utf8" "github.com/TicketsBot-cloud/dashboard/app" "github.com/TicketsBot-cloud/dashboard/app/http/audit" @@ -29,8 +30,8 @@ func UpdateForm(c *gin.Context) { return } - if len(data.Title) > 45 { - c.JSON(400, utils.ErrorStr("Form title must be 45 characters or less (current: %d characters)", len(data.Title))) + if utf8.RuneCountInString(data.Title) > 45 { + c.JSON(400, utils.ErrorStr("Form title must be 45 characters or less (current: %d characters)", utf8.RuneCountInString(data.Title))) return } diff --git a/app/http/endpoints/api/panel/validation.go b/app/http/endpoints/api/panel/validation.go index 9d849f4..8c5b542 100644 --- a/app/http/endpoints/api/panel/validation.go +++ b/app/http/endpoints/api/panel/validation.go @@ -83,7 +83,7 @@ func panelValidators() []validation.Validator[PanelValidationContext] { func validateTitle(ctx PanelValidationContext) validation.ValidationFunc { return func() error { - if len(ctx.Data.Title) > 80 { + if utf8.RuneCountInString(ctx.Data.Title) > 80 { return validation.NewInvalidInputError("Panel title must be less than 80 characters") } @@ -93,7 +93,7 @@ func validateTitle(ctx PanelValidationContext) validation.ValidationFunc { func validateContent(ctx PanelValidationContext) validation.ValidationFunc { return func() error { - if len(ctx.Data.Content) > 4096 { + if utf8.RuneCountInString(ctx.Data.Content) > 4096 { return validation.NewInvalidInputError("Panel content must be less than 4096 characters") } @@ -202,7 +202,7 @@ func validateButtonStyle(ctx PanelValidationContext) validation.ValidationFunc { func validateButtonLabel(ctx PanelValidationContext) validation.ValidationFunc { return func() error { - if len(ctx.Data.ButtonLabel) > 80 { + if utf8.RuneCountInString(ctx.Data.ButtonLabel) > 80 { return validation.NewInvalidInputError("Button label must be less than 80 characters") } @@ -312,7 +312,7 @@ func validateNamingScheme(ctx PanelValidationContext) validation.ValidationFunc return nil } - if len(*ctx.Data.NamingScheme) > 100 { + if utf8.RuneCountInString(*ctx.Data.NamingScheme) > 100 { return validation.NewInvalidInputError("Naming scheme must be less than 100 characters") }