Skip to content

Commit 236e70f

Browse files
authored
Fix escaping issue in diff (#14153)
Ensure that linecontent is escaped before passing to template.HTML Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 5a1ccac commit 236e70f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

services/gitdiff/gitdiff.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"bytes"
1111
"context"
1212
"fmt"
13+
"html"
1314
"html/template"
1415
"io"
1516
"io/ioutil"
@@ -164,9 +165,9 @@ func getDiffLineSectionInfo(treePath, line string, lastLeftIdx, lastRightIdx int
164165
// escape a line's content or return <br> needed for copy/paste purposes
165166
func getLineContent(content string) string {
166167
if len(content) > 0 {
167-
return content
168+
return html.EscapeString(content)
168169
}
169-
return "\n"
170+
return "<br>"
170171
}
171172

172173
// DiffSection represents a section of a DiffFile.
@@ -357,8 +358,6 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) tem
357358
diffRecord := diffMatchPatch.DiffMain(highlight.Code(diffSection.FileName, diff1[1:]), highlight.Code(diffSection.FileName, diff2[1:]), true)
358359
diffRecord = diffMatchPatch.DiffCleanupEfficiency(diffRecord)
359360

360-
diffRecord = diffMatchPatch.DiffCleanupEfficiency(diffRecord)
361-
362361
return diffToHTML(diffSection.FileName, diffRecord, diffLine.Type)
363362
}
364363

0 commit comments

Comments
 (0)