diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 539715b3f9..fbada5472c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1238,6 +1238,7 @@ file_view_rendered = View Rendered file_view_raw = View Raw file_permalink = Permalink file_too_large = The file is too large to be shown. +file_is_empty = The file is empty. code_preview_line_from_to = Lines %[1]d to %[2]d in %[3]s code_preview_line_in = Line %[1]d in %[2]s invisible_runes_header = `This file contains invisible Unicode characters` diff --git a/routers/web/repo/blame.go b/routers/web/repo/blame.go index 1887e4d95d..3e76ea6df4 100644 --- a/routers/web/repo/blame.go +++ b/routers/web/repo/blame.go @@ -99,8 +99,6 @@ func RefBlame(ctx *context.Context) { } ctx.Data["NumLines"], err = blob.GetBlobLineCount() - ctx.Data["NumLinesSet"] = true - if err != nil { ctx.NotFound("GetBlobLineCount", err) return diff --git a/routers/web/repo/setting/lfs.go b/routers/web/repo/setting/lfs.go index 6dddade066..2891556d6f 100644 --- a/routers/web/repo/setting/lfs.go +++ b/routers/web/repo/setting/lfs.go @@ -303,6 +303,7 @@ func LFSFileGet(ctx *context.Context) { rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{}) // Building code view blocks with line number on server side. + // FIXME: the logic is not right here: it first calls EscapeControlReader then calls HTMLEscapeString: double-escaping escapedContent := &bytes.Buffer{} ctx.Data["EscapeStatus"], _ = charset.EscapeControlReader(rd, escapedContent, ctx.Locale) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 386ef7be5c..0aa3fe1efd 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -286,6 +286,7 @@ func renderReadmeFile(ctx *context.Context, subfolder string, readmeFile *git.Tr ctx.Data["FileIsText"] = fInfo.isTextFile ctx.Data["FileName"] = path.Join(subfolder, readmeFile.Name()) + ctx.Data["FileSize"] = fInfo.fileSize ctx.Data["IsLFSFile"] = fInfo.isLFSFile if fInfo.isLFSFile { @@ -301,7 +302,6 @@ func renderReadmeFile(ctx *context.Context, subfolder string, readmeFile *git.Tr // Pretend that this is a normal text file to display 'This file is too large to be shown' ctx.Data["IsFileTooLarge"] = true ctx.Data["IsTextFile"] = true - ctx.Data["FileSize"] = fInfo.fileSize return } @@ -552,7 +552,6 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) { } else { ctx.Data["NumLines"] = bytes.Count(buf, []byte{'\n'}) + 1 } - ctx.Data["NumLinesSet"] = true language, err := files_service.TryGetContentLanguage(ctx.Repo.GitRepo, ctx.Repo.CommitID, ctx.Repo.TreePath) if err != nil { @@ -606,8 +605,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) { break } - // TODO: this logic seems strange, it duplicates with "isRepresentableAsText=true", it is not the same as "LFSFileGet" in "lfs.go" - // maybe for this case, the file is a binary file, and shouldn't be rendered? + // TODO: this logic duplicates with "isRepresentableAsText=true", it is not the same as "LFSFileGet" in "lfs.go" + // It is used by "external renders", markupRender will execute external programs to get rendered content. if markupType := markup.Type(blob.Name()); markupType != "" { rd := io.MultiReader(bytes.NewReader(buf), dataRc) ctx.Data["IsMarkup"] = true diff --git a/templates/repo/blame.tmpl b/templates/repo/blame.tmpl index 4ad3ed85c9..3e7cd92066 100644 --- a/templates/repo/blame.tmpl +++ b/templates/repo/blame.tmpl @@ -32,6 +32,8 @@