Skip to content

Commit 39efe44

Browse files
wxiaoguangGiteaBot
authored andcommitted
Fix the topic validation rule and suport dots (go-gitea#26286)
1. Allow leading and trailing spaces by user input, these spaces have already been trimmed at backend 2. Allow using dots in the topic
1 parent a758337 commit 39efe44

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

models/repo/topic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func init() {
2222
db.RegisterModel(new(RepoTopic))
2323
}
2424

25-
var topicPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
25+
var topicPattern = regexp.MustCompile(`^[a-z0-9][-.a-z0-9]*$`)
2626

2727
// Topic represents a topic of repositories
2828
type Topic struct {

models/repo/topic_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TestAddTopic(t *testing.T) {
6969
func TestTopicValidator(t *testing.T) {
7070
assert.True(t, repo_model.ValidateTopic("12345"))
7171
assert.True(t, repo_model.ValidateTopic("2-test"))
72+
assert.True(t, repo_model.ValidateTopic("foo.bar"))
7273
assert.True(t, repo_model.ValidateTopic("test-3"))
7374
assert.True(t, repo_model.ValidateTopic("first"))
7475
assert.True(t, repo_model.ValidateTopic("second-test-topic"))
@@ -77,4 +78,5 @@ func TestTopicValidator(t *testing.T) {
7778
assert.False(t, repo_model.ValidateTopic("$fourth-test,topic"))
7879
assert.False(t, repo_model.ValidateTopic("-fifth-test-topic"))
7980
assert.False(t, repo_model.ValidateTopic("sixth-go-project-topic-with-excess-length"))
81+
assert.False(t, repo_model.ValidateTopic(".foo"))
8082
}

options/locale/locale_en-US.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -2484,7 +2484,7 @@ tag.create_success = Tag "%s" has been created.
24842484
topic.manage_topics = Manage Topics
24852485
topic.done = Done
24862486
topic.count_prompt = You cannot select more than 25 topics
2487-
topic.format_prompt = Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2487+
topic.format_prompt = Topics must start with a letter or number, can include dashes ('-') and dots ('.'), can be up to 35 characters long. Letters must be lowercase.
24882488

24892489
find_file.go_to_file = Go to file
24902490
find_file.no_matching = No matching file found

web_src/js/features/repo-home.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export function initRepoTopicBar() {
166166
rules: [
167167
{
168168
type: 'validateTopic',
169-
value: /^[a-z0-9][a-z0-9-]{0,35}$/,
169+
value: /^\s*[a-z0-9][-.a-z0-9]{0,35}\s*$/,
170170
prompt: topicPrompts.formatPrompt
171171
},
172172
{

0 commit comments

Comments
 (0)