aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gogs.go2
-rw-r--r--modules/base/tool.go4
-rw-r--r--routers/repo/editor.go4
-rw-r--r--routers/repo/view.go9
-rw-r--r--templates/.VERSION2
5 files changed, 10 insertions, 11 deletions
diff --git a/gogs.go b/gogs.go
index 04689d4544..2599a4c1d6 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 e321d2b868..52d1e178db 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 bf2244719c..428a25d568 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 055785564d..c04ef1ee3f 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 60a098b413..b976997b57 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