aboutsummaryrefslogtreecommitdiffstats
path: root/modules/references/references_test.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-11-09 22:57:47 +0000
committerGitHub <noreply@github.com>2020-11-10 00:57:47 +0200
commit77e5081a2e3aaf1b60033e04fbe2c82e2f918d69 (patch)
treea60d9ebf407ea29dd32ac048403e31826999b764 /modules/references/references_test.go
parentffa712e783ffbb4b3a79ca79c55dac5fde384e22 (diff)
downloadgitea-77e5081a2e3aaf1b60033e04fbe2c82e2f918d69.tar.gz
gitea-77e5081a2e3aaf1b60033e04fbe2c82e2f918d69.zip
Fix panic bug in handling multiple references in commit (#13486)
* Fix panic bug in handling multiple references in commit The issue lay in determining the position of matches on a second run round a commit message in FindAllIssueReferences. Fix #13483 Signed-off-by: Andrew Thornton <art27@cantab.net> * Extract function and make testable Signed-off-by: Andrew Thornton <art27@cantab.net> * Fix the comment Signed-off-by: Andrew Thornton <art27@cantab.net> * cleaning up the comments a bit more Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/references/references_test.go')
-rw-r--r--modules/references/references_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/modules/references/references_test.go b/modules/references/references_test.go
index 0c4037f120..f51379e4c3 100644
--- a/modules/references/references_test.go
+++ b/modules/references/references_test.go
@@ -5,6 +5,7 @@
package references
import (
+ "regexp"
"testing"
"code.gitea.io/gitea/modules/setting"
@@ -29,6 +30,26 @@ type testResult struct {
TimeLog string
}
+func TestConvertFullHTMLReferencesToShortRefs(t *testing.T) {
+ re := regexp.MustCompile(`(\s|^|\(|\[)` +
+ regexp.QuoteMeta("https://ourgitea.com/git/") +
+ `([0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+)/` +
+ `((?:issues)|(?:pulls))/([0-9]+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
+ test := `this is a https://ourgitea.com/git/owner/repo/issues/123456789, foo
+https://ourgitea.com/git/owner/repo/pulls/123456789
+ And https://ourgitea.com/git/owner/repo/pulls/123
+`
+ expect := `this is a owner/repo#123456789, foo
+owner/repo!123456789
+ And owner/repo!123
+`
+
+ contentBytes := []byte(test)
+ convertFullHTMLReferencesToShortRefs(re, &contentBytes)
+ result := string(contentBytes)
+ assert.EqualValues(t, expect, result)
+}
+
func TestFindAllIssueReferences(t *testing.T) {
fixtures := []testFixture{
@@ -107,6 +128,13 @@ func TestFindAllIssueReferences(t *testing.T) {
},
},
{
+ "This http://gitea.com:3000/user4/repo5/pulls/202 yes. http://gitea.com:3000/user4/repo5/pulls/203 no",
+ []testResult{
+ {202, "user4", "repo5", "202", true, XRefActionNone, nil, nil, ""},
+ {203, "user4", "repo5", "203", true, XRefActionNone, nil, nil, ""},
+ },
+ },
+ {
"This http://GiTeA.COM:3000/user4/repo6/pulls/205 yes.",
[]testResult{
{205, "user4", "repo6", "205", true, XRefActionNone, nil, nil, ""},