Skip to content

Commit

Permalink
fix: remove zero width tags
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Oct 5, 2024
1 parent 2b0fb68 commit b7640f7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
9 changes: 9 additions & 0 deletions internal/collections/infra/mysql_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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]++
}

Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/dam/dam.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ func AllPrintableChar(text string) bool {

return true
}

var ZeroWithPattern = regexp.MustCompile(`\p{Cf}|\p{Cc}|\p{Co}`)
5 changes: 3 additions & 2 deletions internal/subject/mysq_repository_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions web/req/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b7640f7

Please sign in to comment.