]> source.dussan.org Git - gitea.git/commitdiff
Correctly link URLs to users/repos with dashes, dots or underscores (#18890) (#18908)
authorsilverwind <me@silverwind.io>
Sat, 26 Feb 2022 05:45:09 +0000 (06:45 +0100)
committerGitHub <noreply@github.com>
Sat, 26 Feb 2022 05:45:09 +0000 (06:45 +0100)
* 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>
modules/markup/html.go
modules/markup/html_test.go

index 345c99e3b4afdca73fcf10130610df36054c9953..52430a83e4938ad128e151e69d6d93d2223bd474 100644 (file)
@@ -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
 }
index 23d7b44570aee260073ee6ec6e5a724db0c1444a..879e69fc0e7defd534794968be15071f516a19e7 100644 (file)
@@ -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) {