fixed image url validation

Signed-off-by: Ben Hall <ben@benh.codes>
This commit is contained in:
Ben Hall 2025-01-21 21:42:00 +00:00
parent 474a9bd408
commit e7cb111874

View File

@ -172,10 +172,8 @@ var urlRegex = regexp.MustCompile(`^https?://([-a-zA-Z0-9@:%._+~#=]{1,256})\.[a-
func validateNullableUrl(url *string) validation.ValidationFunc {
return func() error {
if url != nil && (len(*url) > 255 || !urlRegex.MatchString(*url)) {
if *url != "%avatar_url%" {
return validation.NewInvalidInputError("Invalid URL")
}
}
return nil
}
@ -361,6 +359,18 @@ func validateAccessControlList(ctx PanelValidationContext) validation.Validation
func validateEmbed(e *types.CustomEmbed) error {
if e == nil || e.Title != nil || e.Description != nil || len(e.Fields) > 0 || e.ImageUrl != nil || e.ThumbnailUrl != nil {
if e.ImageUrl != nil && (len(*e.ImageUrl) > 255 || !urlRegex.MatchString(*e.ImageUrl)) {
if *e.ImageUrl != "%avatar_url%" {
return validation.NewInvalidInputError("Invalid URL")
}
}
if e.ThumbnailUrl != nil && (len(*e.ThumbnailUrl) > 255 || !urlRegex.MatchString(*e.ThumbnailUrl)) {
if *e.ThumbnailUrl != "%avatar_url%" {
return validation.NewInvalidInputError("Invalid URL")
}
}
return nil
}