Skip to content

Commit 09dc97b

Browse files
committed
- calling template.HTMLEscapeString directly in diffWithHighlight since we dont actually need to highlight the code here
- adding newline in testcase
1 parent 447236e commit 09dc97b

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

services/gitdiff/highlightdiff.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
package gitdiff
55

66
import (
7+
"html/template"
78
"strings"
89

9-
"code.gitea.io/gitea/modules/highlight"
1010
"github.com/sergi/go-diff/diffmatchpatch"
1111
)
1212

@@ -89,11 +89,8 @@ func (hcd *highlightCodeDiff) diffWithHighlight(codeA, codeB string) []diffmatch
8989
hcd.collectUsedRunes(codeA)
9090
hcd.collectUsedRunes(codeB)
9191

92-
highlightCodeA, _ := highlight.Code("", "", codeA)
93-
highlightCodeB, _ := highlight.Code("", "", codeB)
94-
95-
convertedCodeA := hcd.convertToPlaceholders(string(highlightCodeA))
96-
convertedCodeB := hcd.convertToPlaceholders(string(highlightCodeB))
92+
convertedCodeA := hcd.convertToPlaceholders(template.HTMLEscapeString(codeA))
93+
convertedCodeB := hcd.convertToPlaceholders(template.HTMLEscapeString(codeB))
9794

9895
diffs := diffMatchPatch.DiffMain(convertedCodeA, convertedCodeB, true)
9996
diffs = diffMatchPatch.DiffCleanupEfficiency(diffs)

services/gitdiff/highlightdiff_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ func TestDiffWithHighlight(t *testing.T) {
1919
" run(db)\n",
2020
)
2121

22-
expected := ` run(<span class="removed-code">&#39;&lt;&gt;&#39;</span>)`
22+
expected := "\t\trun(<span class=\"removed-code\">&#39;&lt;&gt;&#39;</span>)\n"
2323
output := diffToHTML(nil, diffs, DiffLineDel)
2424
assert.Equal(t, expected, output)
2525

26-
expected = ` run(<span class="added-code">db</span>)`
26+
expected = "\t\trun(<span class=\"added-code\">db</span>)\n"
2727
output = diffToHTML(nil, diffs, DiffLineAdd)
2828
assert.Equal(t, expected, output)
2929

0 commit comments

Comments
 (0)