Skip to content

Commit

Permalink
fix: restrict length of tag name
Browse files Browse the repository at this point in the history
  • Loading branch information
ppolariss committed Jul 12, 2024
1 parent 1ba6d58 commit 93c99fc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions models/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,17 @@ func FindOrCreateTags(tx *gorm.DB, user *User, names []string) (Tags, error) {
return tags, nil
}
for _, tag := range newTags {
if strings.HasPrefix(tag.Name, "#") {
if !user.IsAdmin {
if !user.IsAdmin {
if len(tag.Name) > 15 {
return nil, common.BadRequest("标签长度不能超过 15 个字符")
}
if strings.HasPrefix(tag.Name, "#") {
return nil, common.BadRequest("只有管理员才能创建 # 开头的 tag")
}
}
if strings.HasPrefix(tag.Name, "@") {
if !user.IsAdmin {
if strings.HasPrefix(tag.Name, "@") {
return nil, common.BadRequest("只有管理员才能创建 @ 开头的 tag")
}
}
if strings.HasPrefix(tag.Name, "*") {
if !user.IsAdmin {
if strings.HasPrefix(tag.Name, "*") {
return nil, common.BadRequest("只有管理员才能创建 * 开头的 tag")
}
}
Expand Down

0 comments on commit 93c99fc

Please sign in to comment.