diff --git a/internal/collections/infra/mysql_repo.go b/internal/collections/infra/mysql_repo.go index 5b2f1b89a..51265b07e 100644 --- a/internal/collections/infra/mysql_repo.go +++ b/internal/collections/infra/mysql_repo.go @@ -38,6 +38,7 @@ import ( "github.com/bangumi/server/internal/collections" "github.com/bangumi/server/internal/collections/domain/collection" "github.com/bangumi/server/internal/model" + "github.com/bangumi/server/internal/pkg/dam" "github.com/bangumi/server/internal/pkg/gstr" "github.com/bangumi/server/internal/subject" ) @@ -306,6 +307,14 @@ func (r mysqlRepo) reCountSubjectTags(ctx context.Context, tx *query.Query, var count = make(map[string]int) for _, tag := range tagList { + if len(tag.Tag.Name) == 0 { + continue + } + + if dam.ZeroWithPattern.MatchString(tag.Tag.Name) { + continue + } + count[tag.Tag.Name]++ } diff --git a/internal/pkg/dam/dam.go b/internal/pkg/dam/dam.go index 81eb59dd0..6191fb021 100644 --- a/internal/pkg/dam/dam.go +++ b/internal/pkg/dam/dam.go @@ -96,3 +96,5 @@ func AllPrintableChar(text string) bool { return true } + +var ZeroWithPattern = regexp.MustCompile(`\p{Cf}|\p{Cc}|\p{Co}`) diff --git a/internal/subject/mysq_repository_compat.go b/internal/subject/mysq_repository_compat.go index 01a700445..4f5c203e8 100644 --- a/internal/subject/mysq_repository_compat.go +++ b/internal/subject/mysq_repository_compat.go @@ -23,8 +23,9 @@ import ( ) type Tag struct { - Name *string `php:"tag_name"` - Count int `php:"result,string"` + Name *string `php:"tag_name"` + Count int `php:"result,string"` + TotalCount int `php:"tag_results,string"` } func ParseTags(b []byte) ([]model.Tag, error) { diff --git a/web/req/collection.go b/web/req/collection.go index 4387fd3d6..8e4193698 100644 --- a/web/req/collection.go +++ b/web/req/collection.go @@ -51,6 +51,12 @@ func (v *SubjectEpisodeCollectionPatch) Validate() error { if !lo.EveryBy(v.Tags, dam.AllPrintableChar) { return res.BadRequest("invisible character are included in tags") } + + if lo.ContainsBy(v.Tags, func(item string) bool { + return len(item) == 0 + }) { + return res.BadRequest("zero length tags are included in tags") + } } if v.Comment.Set {