summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorguillep2k <18600385+guillep2k@users.noreply.github.com>2019-08-15 09:07:28 -0300
committerLunny Xiao <xiaolunwen@gmail.com>2019-08-15 20:07:28 +0800
commit5a44be627c055d3e9eb406ec4a91579de78b6910 (patch)
tree1a9d4ce34f16bdc02e0ac79a63a81d955ead8e6e /routers
parentc2c35d169c819439b78c8c2c7f8877e7bf053cd1 (diff)
downloadgitea-5a44be627c055d3e9eb406ec4a91579de78b6910.tar.gz
gitea-5a44be627c055d3e9eb406ec4a91579de78b6910.zip
Convert files to utf-8 for indexing (#7814)
* Convert files to utf-8 for indexing * Move utf8 functions to modules/base * Bump repoIndexerLatestVersion to 3 * Add tests for base/encoding.go * Changes to pass gosimple * Move UTF8 funcs into new modules/charset package
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/commit.go4
-rw-r--r--routers/repo/editor.go4
-rw-r--r--routers/repo/view.go8
3 files changed, 8 insertions, 8 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index 4dbedea2a0..79fa024dc9 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -11,11 +11,11 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
+ "code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/templates"
)
const (
@@ -251,7 +251,7 @@ func Diff(ctx *context.Context) {
note := &git.Note{}
err = git.GetNote(ctx.Repo.GitRepo, commitID, note)
if err == nil {
- ctx.Data["Note"] = string(templates.ToUTF8WithFallback(note.Message))
+ ctx.Data["Note"] = string(charset.ToUTF8WithFallback(note.Message))
ctx.Data["NoteCommit"] = note.Commit
ctx.Data["NoteAuthor"] = models.ValidateCommitWithEmail(note.Commit)
}
diff --git a/routers/repo/editor.go b/routers/repo/editor.go
index 1c7eee98ac..68b94662dc 100644
--- a/routers/repo/editor.go
+++ b/routers/repo/editor.go
@@ -14,12 +14,12 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/base"
+ "code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repofiles"
"code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/upload"
"code.gitea.io/gitea/modules/util"
)
@@ -118,7 +118,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
d, _ := ioutil.ReadAll(dataRc)
buf = append(buf, d...)
- if content, err := templates.ToUTF8WithErr(buf); err != nil {
+ if content, err := charset.ToUTF8WithErr(buf); err != nil {
log.Error("ToUTF8WithErr: %v", err)
ctx.Data["FileContent"] = string(buf)
} else {
diff --git a/routers/repo/view.go b/routers/repo/view.go
index edaf24017c..b534ae0e16 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
+ "code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/highlight"
@@ -23,7 +24,6 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/templates"
)
const (
@@ -160,7 +160,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
ctx.Data["FileSize"] = fileSize
} else {
d, _ := ioutil.ReadAll(dataRc)
- buf = templates.ToUTF8WithFallback(append(buf, d...))
+ buf = charset.ToUTF8WithFallback(append(buf, d...))
if markup.Type(readmeFile.Name()) != "" {
ctx.Data["IsMarkup"] = true
@@ -278,7 +278,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
}
d, _ := ioutil.ReadAll(dataRc)
- buf = templates.ToUTF8WithFallback(append(buf, d...))
+ buf = charset.ToUTF8WithFallback(append(buf, d...))
readmeExist := markup.IsReadmeFile(blob.Name())
ctx.Data["ReadmeExist"] = readmeExist
@@ -293,7 +293,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
} else {
// Building code view blocks with line number on server side.
var fileContent string
- if content, err := templates.ToUTF8WithErr(buf); err != nil {
+ if content, err := charset.ToUTF8WithErr(buf); err != nil {
log.Error("ToUTF8WithErr: %v", err)
fileContent = string(buf)
} else {