forked from forgejo/forgejo
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>
This commit is contained in:
parent
ffa712e783
commit
77e5081a2e
2 changed files with 95 additions and 29 deletions
|
@ -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{
|
||||
|
@ -106,6 +127,13 @@ func TestFindAllIssueReferences(t *testing.T) {
|
|||
{202, "user4", "repo5", "202", true, XRefActionNone, nil, nil, ""},
|
||||
},
|
||||
},
|
||||
{
|
||||
"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{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue