|
|
@@ -8,6 +8,7 @@ import ( |
|
|
|
"fmt" |
|
|
|
"regexp" |
|
|
|
"strings" |
|
|
|
"unicode/utf8" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
|
|
|
|
@@ -21,12 +22,12 @@ func init() { |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
var topicPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`) |
|
|
|
var topicPattern = regexp.MustCompile(`^[\x{4e00}-\x{9fa5}a-z0-9][\x{4e00}-\x{9fa5}a-z0-9-]*$`) |
|
|
|
|
|
|
|
// Topic represents a topic of repositories |
|
|
|
type Topic struct { |
|
|
|
ID int64 |
|
|
|
Name string `xorm:"UNIQUE VARCHAR(25)"` |
|
|
|
Name string `xorm:"UNIQUE VARCHAR(105)"` |
|
|
|
RepoCount int |
|
|
|
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` |
|
|
|
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` |
|
|
@@ -56,7 +57,7 @@ func (err ErrTopicNotExist) Error() string { |
|
|
|
|
|
|
|
// ValidateTopic checks a topic by length and match pattern rules |
|
|
|
func ValidateTopic(topic string) bool { |
|
|
|
return len(topic) <= 35 && topicPattern.MatchString(topic) |
|
|
|
return utf8.RuneCountInString(topic) <= 35 && topicPattern.MatchString(topic) |
|
|
|
} |
|
|
|
|
|
|
|
// SanitizeAndValidateTopics sanitizes and checks an array or topics |
|
|
|