1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-02 08:57:32 -04:00

#2282 fix utf-8 recognized as windows-1252

This commit is contained in:
Unknwon 2015-12-25 05:25:47 -05:00
parent 13fe733037
commit 85af36332b
6 changed files with 13 additions and 10 deletions

View File

@ -209,7 +209,7 @@ func runServ(c *cli.Context) {
} }
// Check if this deploy key belongs to current repository. // Check if this deploy key belongs to current repository.
if !models.HasDeployKey(key.ID, repo.ID) { if !models.HasDeployKey(key.ID, repo.ID) {
fail("Key access denied", "Key access denied: %d-%d", key.ID, repo.ID) fail("Key access denied", "Key access denied: [key_id: %d, repo_id: %d]", key.ID, repo.ID)
} }
// Update deploy key activity. // Update deploy key activity.

View File

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.8.13.1224" const APP_VER = "0.8.13.1225"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View File

@ -25,6 +25,7 @@ import (
"golang.org/x/net/html/charset" "golang.org/x/net/html/charset"
"github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/avatar"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -52,7 +53,8 @@ func ShortSha(sha1 string) string {
} }
func DetectEncoding(content []byte) string { func DetectEncoding(content []byte) string {
_, name, _ := charset.DetermineEncoding(content, setting.Repository.AnsiCharset) _, name, certain := charset.DetermineEncoding(content, setting.Repository.AnsiCharset)
log.Debug("Detected encoding: %s (%v)", name, certain)
return name return name
} }

View File

@ -12,6 +12,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"time" "time"
"unicode/utf8"
"golang.org/x/net/html/charset" "golang.org/x/net/html/charset"
"golang.org/x/text/transform" "golang.org/x/text/transform"
@ -130,20 +131,19 @@ func Sha1(str string) string {
} }
func ToUtf8WithErr(content []byte) (error, string) { func ToUtf8WithErr(content []byte) (error, string) {
charsetLabel := base.DetectEncoding(content) if utf8.Valid(content[:1024]) {
if charsetLabel == "UTF-8" {
return nil, string(content) return nil, string(content)
} }
charsetLabel := base.DetectEncoding(content)
encoding, _ := charset.Lookup(charsetLabel) encoding, _ := charset.Lookup(charsetLabel)
if encoding == nil { if encoding == nil {
return fmt.Errorf("unknown char decoder %s", charsetLabel), string(content) return fmt.Errorf("Unknown encoding: %s", charsetLabel), string(content)
} }
result, n, err := transform.String(encoding.NewDecoder(), string(content))
// If there is an error, we concatenate the nicely decoded part and the // If there is an error, we concatenate the nicely decoded part and the
// original left over. This way we won't loose data. // original left over. This way we won't loose data.
result, n, err := transform.String(encoding.NewDecoder(), string(content))
if err != nil { if err != nil {
result = result + string(content[n:]) result = result + string(content[n:])
} }

View File

@ -6,6 +6,7 @@ package user
import ( import (
"fmt" "fmt"
"path"
"strings" "strings"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
@ -38,7 +39,7 @@ func Profile(ctx *middleware.Context) {
uname := ctx.Params(":username") uname := ctx.Params(":username")
// Special handle for FireFox requests favicon.ico. // Special handle for FireFox requests favicon.ico.
if uname == "favicon.ico" { if uname == "favicon.ico" {
ctx.Redirect(setting.AppSubUrl + "/img/favicon.png") ctx.ServeFile(path.Join(setting.StaticRootPath, "public/img/favicon.png"))
return return
} else if strings.HasSuffix(uname, ".png") { } else if strings.HasSuffix(uname, ".png") {
ctx.Error(404) ctx.Error(404)

View File

@ -1 +1 @@
0.8.13.1224 0.8.13.1225