Skip to content

Commit

Permalink
Prevent NPE on partial match of compare URL (part 2)
Browse files Browse the repository at this point in the history
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 <art27@cantab.net>
  • Loading branch information
zeripath committed Jan 31, 2022
1 parent db7c3ec commit d4dfa50
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,9 @@ func comparePatternProcessor(ctx *RenderContext, node *html.Node) {
}

// Ensure that every group (m[0]...m[7]) has a match
if len(m) < 8 {
return
}
for i := 0; i < 8; i++ {
if m[i] == -1 {
return
Expand All @@ -959,7 +962,7 @@ func comparePatternProcessor(ctx *RenderContext, node *html.Node) {
text2 := base.ShortSha(node.Data[m[6]:m[7]])

hash := ""
if m[9] > 0 {
if len(m) > 9 && m[9] > 0 {
hash = node.Data[m[8]:m[9]][1:]
}

Expand Down

0 comments on commit d4dfa50

Please sign in to comment.