Skip to content

Commit 31086b4

Browse files
committed
Fix bug when viewing the commit diff page with non-ANSI files
1 parent 1e72b15 commit 31086b4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

services/gitdiff/gitdiff.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,18 +1325,19 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit
13251325
shouldFullFileHighlight := !setting.Git.DisableDiffHighlight && attrDiff.Value() == ""
13261326
if shouldFullFileHighlight {
13271327
if limitedContent.LeftContent != nil && limitedContent.LeftContent.buf.Len() < MaxDiffHighlightEntireFileSize {
1328-
diffFile.highlightedLeftLines = highlightCodeLines(diffFile, true /* left */, limitedContent.LeftContent.buf.String())
1328+
diffFile.highlightedLeftLines = highlightCodeLines(diffFile, true /* left */, limitedContent.LeftContent.buf.Bytes())
13291329
}
13301330
if limitedContent.RightContent != nil && limitedContent.RightContent.buf.Len() < MaxDiffHighlightEntireFileSize {
1331-
diffFile.highlightedRightLines = highlightCodeLines(diffFile, false /* right */, limitedContent.RightContent.buf.String())
1331+
diffFile.highlightedRightLines = highlightCodeLines(diffFile, false /* right */, limitedContent.RightContent.buf.Bytes())
13321332
}
13331333
}
13341334
}
13351335

13361336
return diff, nil
13371337
}
13381338

1339-
func highlightCodeLines(diffFile *DiffFile, isLeft bool, content string) map[int]template.HTML {
1339+
func highlightCodeLines(diffFile *DiffFile, isLeft bool, rawContent []byte) map[int]template.HTML {
1340+
content, _ := charset.ToUTF8(rawContent, charset.ConvertOpts{KeepBOM: false})
13401341
highlightedNewContent, _ := highlight.Code(diffFile.Name, diffFile.Language, content)
13411342
splitLines := strings.Split(string(highlightedNewContent), "\n")
13421343
lines := make(map[int]template.HTML, len(splitLines))

0 commit comments

Comments
 (0)