Skip to content

Commit 8646d5d

Browse files
committed
fix processor node range
1 parent 4a11446 commit 8646d5d

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

modules/markup/html.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path"
1111
"path/filepath"
1212
"regexp"
13+
"slices"
1314
"strings"
1415
"sync"
1516

@@ -1006,7 +1007,12 @@ func fullHashPatternProcessor(ctx *RenderContext, node *html.Node) {
10061007
if ctx.Metas == nil {
10071008
return
10081009
}
1009-
for node != nil {
1010+
nodeStop := node.NextSibling
1011+
for node != nodeStop {
1012+
if node.Type != html.TextNode {
1013+
node = node.NextSibling
1014+
continue
1015+
}
10101016
ret, ok := anyHashPatternExtract(node.Data)
10111017
if !ok {
10121018
node = node.NextSibling
@@ -1028,21 +1034,18 @@ func comparePatternProcessor(ctx *RenderContext, node *html.Node) {
10281034
if ctx.Metas == nil {
10291035
return
10301036
}
1031-
1032-
next := node.NextSibling
1033-
for node != nil && node != next {
1037+
nodeStop := node.NextSibling
1038+
for node != nodeStop {
1039+
if node.Type != html.TextNode {
1040+
node = node.NextSibling
1041+
continue
1042+
}
10341043
m := comparePattern.FindStringSubmatchIndex(node.Data)
1035-
if m == nil {
1044+
if m == nil || slices.Contains(m, -1) {
1045+
node = node.NextSibling
10361046
return
10371047
}
10381048

1039-
// Ensure that every group (m[0]...m[7]) has a match
1040-
for i := 0; i < 8; i++ {
1041-
if m[i] == -1 {
1042-
return
1043-
}
1044-
}
1045-
10461049
urlFull := node.Data[m[0]:m[1]]
10471050
text1 := base.ShortSha(node.Data[m[2]:m[3]])
10481051
textDots := base.ShortSha(node.Data[m[4]:m[5]])

modules/markup/html_codepreview.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ func renderCodeBlock(ctx *RenderContext, node *html.Node) (urlPosStart, urlPosSt
6060
}
6161

6262
func codePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
63-
for node != nil {
63+
nodeStop := node.NextSibling
64+
for node != nodeStop {
6465
if node.Type != html.TextNode {
6566
node = node.NextSibling
6667
continue

0 commit comments

Comments
 (0)