mirror of
https://github.com/go-gitea/gitea
synced 2024-09-27 08:46:53 +02:00
fix processor node range
This commit is contained in:
parent
4a11446e83
commit
86abfdc925
@ -10,6 +10,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -1006,7 +1007,12 @@ func fullHashPatternProcessor(ctx *RenderContext, node *html.Node) {
|
|||||||
if ctx.Metas == nil {
|
if ctx.Metas == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for node != nil {
|
nodeStop := node.NextSibling
|
||||||
|
for node != nodeStop {
|
||||||
|
if node.Type != html.TextNode {
|
||||||
|
node = node.NextSibling
|
||||||
|
continue
|
||||||
|
}
|
||||||
ret, ok := anyHashPatternExtract(node.Data)
|
ret, ok := anyHashPatternExtract(node.Data)
|
||||||
if !ok {
|
if !ok {
|
||||||
node = node.NextSibling
|
node = node.NextSibling
|
||||||
@ -1028,19 +1034,16 @@ func comparePatternProcessor(ctx *RenderContext, node *html.Node) {
|
|||||||
if ctx.Metas == nil {
|
if ctx.Metas == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
nodeStop := node.NextSibling
|
||||||
next := node.NextSibling
|
for node != nodeStop {
|
||||||
for node != nil && node != next {
|
if node.Type != html.TextNode {
|
||||||
m := comparePattern.FindStringSubmatchIndex(node.Data)
|
node = node.NextSibling
|
||||||
if m == nil {
|
continue
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
m := comparePattern.FindStringSubmatchIndex(node.Data)
|
||||||
// Ensure that every group (m[0]...m[7]) has a match
|
if m == nil || slices.Contains(m[:8], -1) { // ensure that every group (m[0]...m[7]) has a match
|
||||||
for i := 0; i < 8; i++ {
|
node = node.NextSibling
|
||||||
if m[i] == -1 {
|
continue
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
urlFull := node.Data[m[0]:m[1]]
|
urlFull := node.Data[m[0]:m[1]]
|
||||||
|
@ -60,7 +60,8 @@ func renderCodeBlock(ctx *RenderContext, node *html.Node) (urlPosStart, urlPosSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
func codePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
|
func codePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
|
||||||
for node != nil {
|
nodeStop := node.NextSibling
|
||||||
|
for node != nodeStop {
|
||||||
if node.Type != html.TextNode {
|
if node.Type != html.TextNode {
|
||||||
node = node.NextSibling
|
node = node.NextSibling
|
||||||
continue
|
continue
|
||||||
|
@ -700,7 +700,7 @@ func TestIssue18471(t *testing.T) {
|
|||||||
}, strings.NewReader(data), &res)
|
}, strings.NewReader(data), &res)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "<a href=\"http://domain/org/repo/compare/783b039...da951ce\" class=\"compare\"><code class=\"nohighlight\">783b039...da951ce</code></a>", res.String())
|
assert.Equal(t, `<a href="http://domain/org/repo/compare/783b039...da951ce" class="compare"><code class="nohighlight">783b039...da951ce</code></a>`, res.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsFullURL(t *testing.T) {
|
func TestIsFullURL(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user