From dadd35b63647327bed02719f6cda5d25256fa49e Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 31 Aug 2016 13:59:23 -0700 Subject: [PATCH] #3559 fix template error --- gogs.go | 2 +- modules/base/tool.go | 4 ++++ routers/repo/editor.go | 4 +--- routers/repo/view.go | 9 +++------ templates/.VERSION | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/gogs.go b/gogs.go index 04689d454..2599a4c1d 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.9.97.0830" +const APP_VER = "0.9.97.0831" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/modules/base/tool.go b/modules/base/tool.go index e321d2b86..52d1e178d 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -518,7 +518,11 @@ func IsLetter(ch rune) bool { return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= 0x80 && unicode.IsLetter(ch) } +// IsTextFile returns true if file content format is plain text or empty. func IsTextFile(data []byte) bool { + if len(data) == 0 { + return true + } return strings.Index(http.DetectContentType(data), "text/") != -1 } diff --git a/routers/repo/editor.go b/routers/repo/editor.go index bf2244719..428a25d56 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -64,9 +64,7 @@ func editFile(ctx *context.Context, isNewFile bool) { buf := make([]byte, 1024) n, _ := dataRc.Read(buf) - if n > 0 { - buf = buf[:n] - } + buf = buf[:n] // Only text file are editable online. if !base.IsTextFile(buf) { diff --git a/routers/repo/view.go b/routers/repo/view.go index 055785564..c04ef1ee3 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -64,6 +64,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { } if readmeFile != nil { + ctx.Data["RawFileLink"] = "" ctx.Data["ReadmeInList"] = true ctx.Data["ReadmeExist"] = true @@ -75,9 +76,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { buf := make([]byte, 1024) n, _ := dataRc.Read(buf) - if n > 0 { - buf = buf[:n] - } + buf = buf[:n] isTextFile := base.IsTextFile(buf) ctx.Data["FileIsText"] = isTextFile @@ -134,9 +133,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st buf := make([]byte, 1024) n, _ := dataRc.Read(buf) - if n > 0 { - buf = buf[:n] - } + buf = buf[:n] isTextFile := base.IsTextFile(buf) ctx.Data["IsTextFile"] = isTextFile diff --git a/templates/.VERSION b/templates/.VERSION index 60a098b41..b976997b5 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.9.97.0830 \ No newline at end of file +0.9.97.0831 \ No newline at end of file