mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-07 02:45:22 +02:00
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
This commit is contained in:
parent
c2c35d169c
commit
5a44be627c
13 changed files with 371 additions and 166 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue