Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the topic validation rule and suport dots (#26286) #26303

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/repo/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions models/repo/topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))
}
2 changes: 1 addition & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2484,7 +2484,7 @@ tag.create_success = Tag "%s" has been created.
topic.manage_topics = Manage Topics
topic.done = Done
topic.count_prompt = You cannot select more than 25 topics
topic.format_prompt = Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
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.

find_file.go_to_file = Go to file
find_file.no_matching = No matching file found
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/repo-home.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function initRepoTopicBar() {
rules: [
{
type: 'validateTopic',
value: /^[a-z0-9][a-z0-9-]{0,35}$/,
value: /^\s*[a-z0-9][-.a-z0-9]{0,35}\s*$/,
prompt: topicPrompts.formatPrompt
},
{
Expand Down