Skip to content

Commit

Permalink
fix: filter zero width unicode in tags
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Oct 7, 2024
1 parent 7c65126 commit 4efaf8e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion web/req/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
"strings"
"unicode/utf8"

"github.com/samber/lo"
"golang.org/x/text/unicode/norm"

"github.com/bangumi/server/internal/collections/domain/collection"
"github.com/bangumi/server/internal/pkg/dam"
"github.com/bangumi/server/internal/pkg/null"
Expand Down Expand Up @@ -46,18 +49,23 @@ func (v *SubjectEpisodeCollectionPatch) Validate() error {
}
}

v.Tags = lo.Map(v.Tags, func(item string, index int) string {
return norm.NFKC.String(item)
})

for _, tag := range v.Tags {
if !dam.ValidateTag(tag) {
return res.BadRequest(fmt.Sprintf("invalid tag: %q", tag))
}
}

if v.Comment.Set {
v.Comment.Value = norm.NFKC.String(v.Comment.Value)
v.Comment.Value = strings.TrimSpace(v.Comment.Value)
if !dam.AllPrintableChar(v.Comment.Value) {
return res.BadRequest("invisible character are included in comment")
}

v.Comment.Value = strings.TrimSpace(v.Comment.Value)
if utf8.RuneCountInString(v.Comment.Value) > 380 {
return res.BadRequest("comment too long, only allow less equal than 380 characters")
}
Expand Down

0 comments on commit 4efaf8e

Please sign in to comment.