aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2023-08-04 13:00:49 +0800
committerGitHub <noreply@github.com>2023-08-04 13:00:49 +0800
commitfcd055c34a21095123d6fc18449e855b6c626bec (patch)
treeb0d8cfda1de64fa77bec304b593792b8655776a2 /models
parenta57568bad7dac3c818d01a5b75fe66ce83bf140f (diff)
downloadgitea-fcd055c34a21095123d6fc18449e855b6c626bec.tar.gz
gitea-fcd055c34a21095123d6fc18449e855b6c626bec.zip
Fix the topic validation rule and suport dots (#26286) (#26303)
Backport #26286 by @wxiaoguang 1. Allow leading and trailing spaces by user input, these spaces have already been trimmed at backend 2. Allow using dots in the topic Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'models')
-rw-r--r--models/repo/topic.go2
-rw-r--r--models/repo/topic_test.go2
2 files changed, 3 insertions, 1 deletions
diff --git a/models/repo/topic.go b/models/repo/topic.go
index ec3de869d5..71302388b9 100644
--- a/models/repo/topic.go
+++ b/models/repo/topic.go
@@ -22,7 +22,7 @@ func init() {
db.RegisterModel(new(RepoTopic))
}
-var topicPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
+var topicPattern = regexp.MustCompile(`^[a-z0-9][-.a-z0-9]*$`)
// Topic represents a topic of repositories
type Topic struct {
diff --git a/models/repo/topic_test.go b/models/repo/topic_test.go
index 8a8728168d..aaed91bdd3 100644
--- a/models/repo/topic_test.go
+++ b/models/repo/topic_test.go
@@ -69,6 +69,7 @@ func TestAddTopic(t *testing.T) {
func TestTopicValidator(t *testing.T) {
assert.True(t, repo_model.ValidateTopic("12345"))
assert.True(t, repo_model.ValidateTopic("2-test"))
+ assert.True(t, repo_model.ValidateTopic("foo.bar"))
assert.True(t, repo_model.ValidateTopic("test-3"))
assert.True(t, repo_model.ValidateTopic("first"))
assert.True(t, repo_model.ValidateTopic("second-test-topic"))
@@ -77,4 +78,5 @@ func TestTopicValidator(t *testing.T) {
assert.False(t, repo_model.ValidateTopic("$fourth-test,topic"))
assert.False(t, repo_model.ValidateTopic("-fifth-test-topic"))
assert.False(t, repo_model.ValidateTopic("sixth-go-project-topic-with-excess-length"))
+ assert.False(t, repo_model.ValidateTopic(".foo"))
}