aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsilverwind2022-02-26 06:45:09 +0100
committerGitHub2022-02-26 06:45:09 +0100
commitce75461380adae8fd6d13b21f3820afbdd308ff1 (patch)
tree1fbb674a41083893c05a3b8bb9e79227847ed409
parentcea85c30a455cc91f230856c49b39fc60f6a10ca (diff)
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 <62751754+rtpt-alexanderneumann@users.noreply.github.com>
-rw-r--r--modules/markup/html.go2
-rw-r--r--modules/markup/html_test.go9
2 files changed, 10 insertions, 1 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go
index 345c99e3b..52430a83e 100644
--- a/modules/markup/html.go
+++ b/modules/markup/html.go
@@ -99,7 +99,7 @@ var issueFullPatternOnce sync.Once
func getIssueFullPattern() *regexp.Regexp {
issueFullPatternOnce.Do(func() {
issueFullPattern = regexp.MustCompile(regexp.QuoteMeta(setting.AppURL) +
- `\w+/\w+/(?:issues|pulls)/((?:\w{1,10}-)?[1-9][0-9]*)([\?|#](\S+)?)?\b`)
+ `[\w_.-]+/[\w_.-]+/(?:issues|pulls)/((?:\w{1,10}-)?[1-9][0-9]*)([\?|#](\S+)?)?\b`)
})
return issueFullPattern
}
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index 23d7b4457..879e69fc0 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -95,6 +95,15 @@ func TestRender_CrossReferences(t *testing.T) {
test(
"/home/gitea/go-gitea/gitea#12345",
`<p>/home/gitea/go-gitea/gitea#12345</p>`)
+ test(
+ util.URLJoin(TestAppURL, "gogitea", "gitea", "issues", "12345"),
+ `<p><a href="`+util.URLJoin(TestAppURL, "gogitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/gitea#12345</a></p>`)
+ test(
+ util.URLJoin(TestAppURL, "go-gitea", "gitea", "issues", "12345"),
+ `<p><a href="`+util.URLJoin(TestAppURL, "go-gitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">go-gitea/gitea#12345</a></p>`)
+ test(
+ util.URLJoin(TestAppURL, "gogitea", "some-repo-name", "issues", "12345"),
+ `<p><a href="`+util.URLJoin(TestAppURL, "gogitea", "some-repo-name", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/some-repo-name#12345</a></p>`)
}
func TestMisc_IsSameDomain(t *testing.T) {