]> source.dussan.org Git - gitea.git/commitdiff
#2185 fall back to use custom chardet lib
authorUnknwon <u@gogs.io>
Fri, 1 Jan 2016 03:13:47 +0000 (22:13 -0500)
committerUnknwon <u@gogs.io>
Fri, 1 Jan 2016 03:13:47 +0000 (22:13 -0500)
.gopmfile
README.md
gogs.go
models/git_diff.go
modules/base/tool.go
modules/template/template.go
templates/.VERSION
templates/base/footer.tmpl

index e249d2bd9f43be55f4e3416374fa3f10966a027d..ddd761705c0bbe6e42a816d1ddc034fb13e75981 100644 (file)
--- a/.gopmfile
+++ b/.gopmfile
@@ -16,6 +16,7 @@ github.com/go-macaron/toolbox = commit:ab30a81
 github.com/go-sql-driver/mysql = commit:d512f20
 github.com/go-xorm/core = commit:acb6f00
 github.com/go-xorm/xorm = commit:a8fba4d
+github.com/gogits/chardet = commit:2404f77725
 github.com/gogits/git-module = commit:5cd57b9
 github.com/gogits/go-gogs-client = commit:78460e9
 github.com/issue9/identicon = commit:f8c0d2c
index ef080422ea093f02099bc855bdf932fa97280992..59c07c24773a6569375ffcd070a84c4d2cc82640 100644 (file)
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
 
 ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
 
-##### Current version: 0.8.14
+##### Current version: 0.8.15
 
 | Web | UI  | Preview  |
 |:-------------:|:-------:|:-------:|
diff --git a/gogs.go b/gogs.go
index 5323cfa410942dcb630936200ddc19874fa85297..5ad60cf511e3f3f5fcd7ac0a97c5da4614f1ead0 100644 (file)
--- a/gogs.go
+++ b/gogs.go
@@ -17,7 +17,7 @@ import (
        "github.com/gogits/gogs/modules/setting"
 )
 
-const APP_VER = "0.8.14.1230"
+const APP_VER = "0.8.15.1231"
 
 func init() {
        runtime.GOMAXPROCS(runtime.NumCPU())
index 1b2fb5f2b1de8e7c9e3d98b3d9c4f21138aa99b3..22075ef76b6563ec0079c541c4b72ae26f1a1c9f 100644 (file)
@@ -246,8 +246,8 @@ func ParsePatch(maxlines int, reader io.Reader) (*Diff, error) {
                                buf.WriteString("\n")
                        }
                }
-               charsetLabel := base.DetectEncoding(buf.Bytes())
-               if charsetLabel != "UTF-8" {
+               charsetLabel, err := base.DetectEncoding(buf.Bytes())
+               if charsetLabel != "UTF-8" && err == nil {
                        encoding, _ := charset.Lookup(charsetLabel)
                        if encoding != nil {
                                d := encoding.NewDecoder()
index 5927dad01c6578f506b0bfe836332796f665b96a..255c34ef5af7eed1fa55dab931d81c2d40fa0f5c 100644 (file)
@@ -23,7 +23,8 @@ import (
        "github.com/Unknwon/com"
        "github.com/Unknwon/i18n"
        "github.com/microcosm-cc/bluemonday"
-       "golang.org/x/net/html/charset"
+
+       "github.com/gogits/chardet"
 
        "github.com/gogits/gogs/modules/avatar"
        "github.com/gogits/gogs/modules/log"
@@ -53,19 +54,20 @@ func ShortSha(sha1 string) string {
        return sha1
 }
 
-func DetectEncoding(content []byte) string {
-       if utf8.Valid(content[:1024]) {
+func DetectEncoding(content []byte) (string, error) {
+       if utf8.Valid(content) {
                log.Debug("Detected encoding: utf-8 (fast)")
-               return "utf-8"
+               return "UTF-8", nil
        }
 
-       _, name, certain := charset.DetermineEncoding(content, "")
-       if name != "utf-8" && len(setting.Repository.AnsiCharset) > 0 {
+       result, err := chardet.NewTextDetector().DetectBest(content)
+       if result.Charset != "UTF-8" && len(setting.Repository.AnsiCharset) > 0 {
                log.Debug("Using default AnsiCharset: %s", setting.Repository.AnsiCharset)
-               return setting.Repository.AnsiCharset
+               return setting.Repository.AnsiCharset, err
        }
-       log.Debug("Detected encoding: %s (%v)", name, certain)
-       return name
+
+       log.Debug("Detected encoding: %s", result.Charset)
+       return result.Charset, err
 }
 
 func BasicAuthDecode(encoded string) (string, string, error) {
index 6c070b70096d382145a5afdfbcc126ae5a189e33..6099fcc9871327cd0fa8f1f0d538c64b15dbdf71 100644 (file)
@@ -130,8 +130,10 @@ func Sha1(str string) string {
 }
 
 func ToUtf8WithErr(content []byte) (error, string) {
-       charsetLabel := base.DetectEncoding(content)
-       if charsetLabel == "utf-8" {
+       charsetLabel, err := base.DetectEncoding(content)
+       if err != nil {
+               return err, ""
+       } else if charsetLabel == "UTF-8" {
                return nil, string(content)
        }
 
index b5c863bb9d775017a01574dd4b9266875c595de3..cfcdb254d14ad931f1ef7ceec3bd7fb7d176ae27 100644 (file)
@@ -1 +1 @@
-0.8.14.1230
\ No newline at end of file
+0.8.15.1231
\ No newline at end of file
index 9bbaf7c7a9e0485dcfca3ac1884b5017b3ce8902..5f2e8da03f0aa17ed8d96c6a77c7843db2dbdaf6 100644 (file)
@@ -7,7 +7,7 @@
        <footer>
                <div class="ui container">
                        <div class="ui left">
-                               © 2015 Gogs {{if (or .ShowFooterVersion .PageIsAdmin)}}{{.i18n.Tr "version"}}: {{AppVer}}{{end}} {{.i18n.Tr "page"}}: <strong>{{LoadTimes .PageStartTime}}</strong> {{.i18n.Tr "template"}}: <strong>{{call .TmplLoadTimes}}</strong>
+                               © 2016 Gogs {{if (or .ShowFooterVersion .PageIsAdmin)}}{{.i18n.Tr "version"}}: {{AppVer}}{{end}} {{.i18n.Tr "page"}}: <strong>{{LoadTimes .PageStartTime}}</strong> {{.i18n.Tr "template"}}: <strong>{{call .TmplLoadTimes}}</strong>
                        </div>
                        <div class="ui right links">
                                {{if .ShowFooterBranding}}