diff options
author | Lauris BH <lauris@nix.lv> | 2018-09-29 11:33:54 +0300 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2018-09-29 16:33:54 +0800 |
commit | 81702e6ec9d5bd9d2185a8cb5a021047314baee9 (patch) | |
tree | bd0dbdbb7a1d7505809457c72882d00818a50875 /routers | |
parent | 67806611923eee071513a74671bc00429c3a89fa (diff) | |
download | gitea-81702e6ec9d5bd9d2185a8cb5a021047314baee9.tar.gz gitea-81702e6ec9d5bd9d2185a8cb5a021047314baee9.zip |
Detect charset and convert non UTF-8 files for display (#4950)
* Detect charset and convert non UTF-8 files for display
* Refactor and move function to correct module
* Revert unrelated changes
* More unrelated changes
* Duplicate content for small text to have better encoding detection
* Check if original content is valid before duplicating it
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/view.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/routers/repo/view.go b/routers/repo/view.go index ff5c1afb49..210eb9fe5f 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -25,6 +25,7 @@ import ( "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" + "github.com/Unknwon/paginater" ) @@ -99,7 +100,8 @@ func renderDirectory(ctx *context.Context, treeLink string) { ctx.Data["FileSize"] = readmeFile.Size() } else { d, _ := ioutil.ReadAll(dataRc) - buf = append(buf, d...) + buf = templates.ToUTF8WithFallback(append(buf, d...)) + if markup.Type(readmeFile.Name()) != "" { ctx.Data["IsMarkup"] = true ctx.Data["FileContent"] = string(markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas())) @@ -203,7 +205,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st } d, _ := ioutil.ReadAll(dataRc) - buf = append(buf, d...) + buf = templates.ToUTF8WithFallback(append(buf, d...)) readmeExist := markup.IsReadmeFile(blob.Name()) ctx.Data["ReadmeExist"] = readmeExist |