From 7232ebc2800d7f9cd840f92df67daee804bba42c Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 25 Feb 2022 09:27:34 +0100 Subject: [PATCH 1/2] Add tests for references with dashes This commit adds tests for full URLs referencing repos names and user names containing a dash. --- modules/markup/html_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 29bf6c8fcbc63..f6aabc6272e4d 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -97,6 +97,15 @@ func TestRender_CrossReferences(t *testing.T) { test( "/home/gitea/go-gitea/gitea#12345", `

/home/gitea/go-gitea/gitea#12345

`) + test( + util.URLJoin(TestAppURL, "gogitea", "gitea", "issues", "12345"), + `

gogitea/gitea#12345

`) + test( + util.URLJoin(TestAppURL, "go-gitea", "gitea", "issues", "12345"), + `

go-gitea/gitea#12345

`) + test( + util.URLJoin(TestAppURL, "gogitea", "some-repo-name", "issues", "12345"), + `

gogitea/some-repo-name#12345

`) } func TestMisc_IsSameDomain(t *testing.T) { From 729731fcf587110fd3e75cf987757259d3877ca7 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 25 Feb 2022 09:28:10 +0100 Subject: [PATCH 2/2] Extend regex to match URLs to repos/users with dashes --- modules/markup/html.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index df2a159230d2a..758746ef8794e 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 }