Skip to content

Commit ce756af

Browse files
committed
fix
1 parent b95fd7e commit ce756af

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

routers/web/repo/view_file.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,17 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {
241241
// * IsRenderableXxx: some files are rendered by backend "markup" engine, some are rendered by frontend (pdf, 3d)
242242
// * DefaultViewMode: when there is no "display" query parameter, which view mode should be used by default, source or rendered
243243

244-
utf8Reader := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{})
244+
contentReader := io.MultiReader(bytes.NewReader(buf), dataRc)
245+
if fInfo.st.IsRepresentableAsText() {
246+
contentReader = charset.ToUTF8WithFallbackReader(contentReader, charset.ConvertOpts{})
247+
}
245248
switch {
246249
case fInfo.blobOrLfsSize >= setting.UI.MaxDisplayFileSize:
247250
ctx.Data["IsFileTooLarge"] = true
248-
case handleFileViewRenderMarkup(ctx, entry.Name(), fInfo.st, buf, utf8Reader):
251+
case handleFileViewRenderMarkup(ctx, entry.Name(), fInfo.st, buf, contentReader):
249252
// it also sets ctx.Data["FileContent"] and more
250253
ctx.Data["IsMarkup"] = true
251-
case handleFileViewRenderSource(ctx, entry.Name(), attrs, fInfo, utf8Reader):
254+
case handleFileViewRenderSource(ctx, entry.Name(), attrs, fInfo, contentReader):
252255
// it also sets ctx.Data["FileContent"] and more
253256
ctx.Data["IsDisplayingSource"] = true
254257
case handleFileViewRenderImage(ctx, fInfo, buf):

0 commit comments

Comments
 (0)