* Improve efficiency in FindRenderizableReferenceNumeric and getReferences (#16251) * The Fuzzer is running on a non-repo urlprefix which is incorrect for RenderRaw * Make FindRenderizableReferenceNumeric and getReferences more efficient Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> * as per comment on original pr Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
8ac48584ec
commit
b935472cdf
1 changed files with 8 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
||||||
package references
|
package references
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -14,6 +15,8 @@ import (
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/markup/mdstripper"
|
"code.gitea.io/gitea/modules/markup/mdstripper"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
|
"github.com/yuin/goldmark/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -321,7 +324,7 @@ func FindRenderizableReferenceNumeric(content string, prOnly bool) (bool, *Rende
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r := getCrossReference([]byte(content), match[2], match[3], false, prOnly)
|
r := getCrossReference(util.StringToReadOnlyBytes(content), match[2], match[3], false, prOnly)
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -465,17 +468,16 @@ func findAllIssueReferencesBytes(content []byte, links []string) []*rawReference
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCrossReference(content []byte, start, end int, fromLink bool, prOnly bool) *rawReference {
|
func getCrossReference(content []byte, start, end int, fromLink bool, prOnly bool) *rawReference {
|
||||||
refid := string(content[start:end])
|
sep := bytes.IndexAny(content[start:end], "#!")
|
||||||
sep := strings.IndexAny(refid, "#!")
|
|
||||||
if sep < 0 {
|
if sep < 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
isPull := refid[sep] == '!'
|
isPull := content[start+sep] == '!'
|
||||||
if prOnly && !isPull {
|
if prOnly && !isPull {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
repo := refid[:sep]
|
repo := string(content[start : start+sep])
|
||||||
issue := refid[sep+1:]
|
issue := string(content[start+sep+1 : end])
|
||||||
index, err := strconv.ParseInt(issue, 10, 64)
|
index, err := strconv.ParseInt(issue, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
Reference in a new issue