diff options
author | guillep2k <18600385+guillep2k@users.noreply.github.com> | 2019-08-15 09:07:28 -0300 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-08-15 20:07:28 +0800 |
commit | 5a44be627c055d3e9eb406ec4a91579de78b6910 (patch) | |
tree | 1a9d4ce34f16bdc02e0ac79a63a81d955ead8e6e /modules/repofiles/update.go | |
parent | c2c35d169c819439b78c8c2c7f8877e7bf053cd1 (diff) | |
download | gitea-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 'modules/repofiles/update.go')
-rw-r--r-- | modules/repofiles/update.go | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/modules/repofiles/update.go b/modules/repofiles/update.go index 62e2afbc96..ee1b16bce9 100644 --- a/modules/repofiles/update.go +++ b/modules/repofiles/update.go @@ -11,17 +11,17 @@ import ( "path" "strings" - "golang.org/x/net/html/charset" - "golang.org/x/text/transform" - "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/cache" + "code.gitea.io/gitea/modules/charset" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" + + stdcharset "golang.org/x/net/html/charset" + "golang.org/x/text/transform" ) // IdentityOptions for a person's identity like an author or committer @@ -87,15 +87,15 @@ func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string } - encoding, err := base.DetectEncoding(buf) + encoding, err := charset.DetectEncoding(buf) if err != nil { // just default to utf-8 and no bom return "UTF-8", false } if encoding == "UTF-8" { - return encoding, bytes.Equal(buf[0:3], base.UTF8BOM) + return encoding, bytes.Equal(buf[0:3], charset.UTF8BOM) } - charsetEncoding, _ := charset.Lookup(encoding) + charsetEncoding, _ := stdcharset.Lookup(encoding) if charsetEncoding == nil { return "UTF-8", false } @@ -107,7 +107,7 @@ func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string } if n > 2 { - return encoding, bytes.Equal([]byte(result)[0:3], base.UTF8BOM) + return encoding, bytes.Equal([]byte(result)[0:3], charset.UTF8BOM) } return encoding, false @@ -321,10 +321,10 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up content := opts.Content if bom { - content = string(base.UTF8BOM) + content + content = string(charset.UTF8BOM) + content } if encoding != "UTF-8" { - charsetEncoding, _ := charset.Lookup(encoding) + charsetEncoding, _ := stdcharset.Lookup(encoding) if charsetEncoding != nil { result, _, err := transform.String(charsetEncoding.NewEncoder(), content) if err != nil { |