Skip to content

Commit ce75461

Browse files
Correctly link URLs to users/repos with dashes, dots or underscores (#18890) (#18908)
* Add tests for references with dashes This commit adds tests for full URLs referencing repos names and user names containing a dash. * Extend regex to match URLs to repos/users with dashes Co-authored-by: Alexander Neumann <[email protected]>
1 parent cea85c3 commit ce75461

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

modules/markup/html.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var issueFullPatternOnce sync.Once
9999
func getIssueFullPattern() *regexp.Regexp {
100100
issueFullPatternOnce.Do(func() {
101101
issueFullPattern = regexp.MustCompile(regexp.QuoteMeta(setting.AppURL) +
102-
`\w+/\w+/(?:issues|pulls)/((?:\w{1,10}-)?[1-9][0-9]*)([\?|#](\S+)?)?\b`)
102+
`[\w_.-]+/[\w_.-]+/(?:issues|pulls)/((?:\w{1,10}-)?[1-9][0-9]*)([\?|#](\S+)?)?\b`)
103103
})
104104
return issueFullPattern
105105
}

modules/markup/html_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ func TestRender_CrossReferences(t *testing.T) {
9595
test(
9696
"/home/gitea/go-gitea/gitea#12345",
9797
`<p>/home/gitea/go-gitea/gitea#12345</p>`)
98+
test(
99+
util.URLJoin(TestAppURL, "gogitea", "gitea", "issues", "12345"),
100+
`<p><a href="`+util.URLJoin(TestAppURL, "gogitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/gitea#12345</a></p>`)
101+
test(
102+
util.URLJoin(TestAppURL, "go-gitea", "gitea", "issues", "12345"),
103+
`<p><a href="`+util.URLJoin(TestAppURL, "go-gitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">go-gitea/gitea#12345</a></p>`)
104+
test(
105+
util.URLJoin(TestAppURL, "gogitea", "some-repo-name", "issues", "12345"),
106+
`<p><a href="`+util.URLJoin(TestAppURL, "gogitea", "some-repo-name", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/some-repo-name#12345</a></p>`)
98107
}
99108

100109
func TestMisc_IsSameDomain(t *testing.T) {

0 commit comments

Comments
 (0)