Renamed validate function
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
This commit is contained in:
parent
3c4517f039
commit
b166e695cc
|
|
@ -42,7 +42,7 @@ func reformatAndRemoveIncorrectTopics(x *xorm.Engine) (err error) {
|
|||
break
|
||||
}
|
||||
for _, topic := range topics {
|
||||
if models.TopicValidator(topic.Name) {
|
||||
if models.ValidateTopic(topic.Name) {
|
||||
continue
|
||||
}
|
||||
topic.Name = strings.Replace(strings.TrimSpace(strings.ToLower(topic.Name)), " ", "-", -1)
|
||||
|
|
@ -55,7 +55,7 @@ func reformatAndRemoveIncorrectTopics(x *xorm.Engine) (err error) {
|
|||
touchedRepo[id] = struct{}{}
|
||||
}
|
||||
|
||||
if models.TopicValidator(topic.Name) {
|
||||
if models.ValidateTopic(topic.Name) {
|
||||
log.Info("Updating topic: id = %v, name = %v", topic.ID, topic.Name)
|
||||
if _, err := sess.Table("topic").ID(topic.ID).
|
||||
Update(&Topic{Name: topic.Name}); err != nil {
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ func (err ErrTopicNotExist) Error() string {
|
|||
return fmt.Sprintf("topic is not exist [name: %s]", err.Name)
|
||||
}
|
||||
|
||||
// TopicValidator checks topics by length and match pattern rules
|
||||
func TopicValidator(topic string) bool {
|
||||
// ValidateTopic checks topics by length and match pattern rules
|
||||
func ValidateTopic(topic string) bool {
|
||||
return len(topic) <= 35 && topicPattern.MatchString(topic)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,14 +57,14 @@ func TestAddTopic(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTopicValidator(t *testing.T) {
|
||||
assert.True(t, TopicValidator("12345"))
|
||||
assert.True(t, TopicValidator("2-test"))
|
||||
assert.True(t, TopicValidator("test-3"))
|
||||
assert.True(t, TopicValidator("first"))
|
||||
assert.True(t, TopicValidator("second-test-topic"))
|
||||
assert.True(t, TopicValidator("third-project-topic-with-max-length"))
|
||||
assert.True(t, ValidateTopic("12345"))
|
||||
assert.True(t, ValidateTopic("2-test"))
|
||||
assert.True(t, ValidateTopic("test-3"))
|
||||
assert.True(t, ValidateTopic("first"))
|
||||
assert.True(t, ValidateTopic("second-test-topic"))
|
||||
assert.True(t, ValidateTopic("third-project-topic-with-max-length"))
|
||||
|
||||
assert.False(t, TopicValidator("$fourth-test,topic"))
|
||||
assert.False(t, TopicValidator("-fifth-test-topic"))
|
||||
assert.False(t, TopicValidator("sixth-go-project-topic-with-excess-length"))
|
||||
assert.False(t, ValidateTopic("$fourth-test,topic"))
|
||||
assert.False(t, ValidateTopic("-fifth-test-topic"))
|
||||
assert.False(t, ValidateTopic("sixth-go-project-topic-with-excess-length"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func TopicsPost(ctx *context.Context) {
|
|||
topics[i] = topic
|
||||
i++
|
||||
}
|
||||
if !models.TopicValidator(topic) {
|
||||
if !models.ValidateTopic(topic) {
|
||||
invalidTopics = append(invalidTopics, topic)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user