Skip to content

Commit d83421e

Browse files
committed
fix double-escaping
1 parent dd3aaae commit d83421e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

modules/indexer/code/search.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"bytes"
88
"context"
99
"fmt"
10+
"html/template"
1011
"strings"
1112

1213
"code.gitea.io/gitea/modules/highlight"
@@ -27,7 +28,7 @@ type Result struct {
2728

2829
type ResultLine struct {
2930
Num int
30-
FormattedContent string
31+
FormattedContent template.HTML
3132
}
3233

3334
type SearchResultLanguages = internal.SearchResultLanguages
@@ -101,6 +102,7 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
101102
index += len(line)
102103
}
103104

105+
// we should highlight the whole code block first, otherwise it doesn't work well with multiple line highlighting
104106
hl, _ := highlight.Code(result.Filename, "", formattedLinesBuffer.String())
105107
highlightedLines := strings.Split(string(hl), "\n")
106108

@@ -109,7 +111,7 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
109111
}
110112

111113
for i := 0; i < len(lines); i++ {
112-
lines[i].FormattedContent = highlightedLines[i]
114+
lines[i].FormattedContent = template.HTML(highlightedLines[i])
113115
}
114116

115117
return &Result{

0 commit comments

Comments
 (0)