Skip to content

Commit 2a238f8

Browse files
committed
Prevent NPE on partial match of compare URL (part 2) (go-gitea#18490)
Backport go-gitea#18490 Unfortunately go-gitea#18472 only fixed part of the ways a nil pointer can occur in the compare url. We also need to ensure that the match array has all the matches present. Fix go-gitea#18471 Related go-gitea#18472 Signed-off-by: Andrew Thornton <[email protected]>
1 parent d5027b6 commit 2a238f8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/markup/html.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,9 @@ func comparePatternProcessor(ctx *RenderContext, node *html.Node) {
945945
}
946946

947947
// Ensure that every group (m[0]...m[7]) has a match
948+
if len(m) < 8 {
949+
return
950+
}
948951
for i := 0; i < 8; i++ {
949952
if m[i] == -1 {
950953
return
@@ -957,7 +960,7 @@ func comparePatternProcessor(ctx *RenderContext, node *html.Node) {
957960
text2 := base.ShortSha(node.Data[m[6]:m[7]])
958961

959962
hash := ""
960-
if m[9] > 0 {
963+
if len(m) > 9 && m[9] > 0 {
961964
hash = node.Data[m[8]:m[9]][1:]
962965
}
963966

0 commit comments

Comments
 (0)