Fix bug when viewing the commit diff page with non-ANSI files (#36149) (#36150)

Backport #36149
This commit is contained in:
wxiaoguang
2025-12-14 01:14:06 +08:00
committed by GitHub
parent 2dd8ef8368
commit c97b89a662
5 changed files with 147 additions and 183 deletions

View File

@@ -312,11 +312,13 @@ func EditFile(ctx *context.Context) {
ctx.ServerError("ReadAll", err)
return
}
var fileContent string
if content, err := charset.ToUTF8(buf, charset.ConvertOpts{KeepBOM: true}); err != nil {
ctx.Data["FileContent"] = string(buf)
fileContent = string(buf)
} else {
ctx.Data["FileContent"] = content
fileContent = string(content)
}
ctx.Data["FileContent"] = fileContent
}
}