From a9bfb5767c4824c6a961bf6218fa51d9c46f2a6e Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 18 Aug 2024 00:07:53 +0800 Subject: [PATCH] :bug: Fix validator still validating alias when it is blank --- pkg/internal/services/posts.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/internal/services/posts.go b/pkg/internal/services/posts.go index 477369e..9dbbbaf 100644 --- a/pkg/internal/services/posts.go +++ b/pkg/internal/services/posts.go @@ -271,6 +271,10 @@ func EnsurePostCategoriesAndTags(item models.Post) (models.Post, error) { } func NewPost(user models.Account, item models.Post) (models.Post, error) { + if item.Alias != nil && len(*item.Alias) == 0 { + item.Alias = nil + } + if item.Alias != nil { re := regexp.MustCompile(`^[a-z0-9.-]+$`) if !re.MatchString(*item.Alias) { @@ -333,6 +337,10 @@ func NewPost(user models.Account, item models.Post) (models.Post, error) { } func EditPost(item models.Post) (models.Post, error) { + if item.Alias != nil && len(*item.Alias) == 0 { + item.Alias = nil + } + if item.Alias != nil { re := regexp.MustCompile(`^[a-z0-9.-]+$`) if !re.MatchString(*item.Alias) {