Browse Source

#3559 fix template error

Unknwon 3 years ago
parent
commit
dadd35b636
5 changed files with 10 additions and 11 deletions
  1. 1 1
      gogs.go
  2. 4 0
      modules/base/tool.go
  3. 1 3
      routers/repo/editor.go
  4. 3 6
      routers/repo/view.go
  5. 1 1
      templates/.VERSION

+ 1 - 1
gogs.go

@@ -17,7 +17,7 @@ import (
17 17
 	"github.com/gogits/gogs/modules/setting"
18 18
 )
19 19
 
20
-const APP_VER = "0.9.97.0830"
20
+const APP_VER = "0.9.97.0831"
21 21
 
22 22
 func init() {
23 23
 	runtime.GOMAXPROCS(runtime.NumCPU())

+ 4 - 0
modules/base/tool.go

@@ -518,7 +518,11 @@ func IsLetter(ch rune) bool {
518 518
 	return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= 0x80 && unicode.IsLetter(ch)
519 519
 }
520 520
 
521
+// IsTextFile returns true if file content format is plain text or empty.
521 522
 func IsTextFile(data []byte) bool {
523
+	if len(data) == 0 {
524
+		return true
525
+	}
522 526
 	return strings.Index(http.DetectContentType(data), "text/") != -1
523 527
 }
524 528
 

+ 1 - 3
routers/repo/editor.go

@@ -64,9 +64,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
64 64
 
65 65
 		buf := make([]byte, 1024)
66 66
 		n, _ := dataRc.Read(buf)
67
-		if n > 0 {
68
-			buf = buf[:n]
69
-		}
67
+		buf = buf[:n]
70 68
 
71 69
 		// Only text file are editable online.
72 70
 		if !base.IsTextFile(buf) {

+ 3 - 6
routers/repo/view.go

@@ -64,6 +64,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
64 64
 	}
65 65
 
66 66
 	if readmeFile != nil {
67
+		ctx.Data["RawFileLink"] = ""
67 68
 		ctx.Data["ReadmeInList"] = true
68 69
 		ctx.Data["ReadmeExist"] = true
69 70
 
@@ -75,9 +76,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
75 76
 
76 77
 		buf := make([]byte, 1024)
77 78
 		n, _ := dataRc.Read(buf)
78
-		if n > 0 {
79
-			buf = buf[:n]
80
-		}
79
+		buf = buf[:n]
81 80
 
82 81
 		isTextFile := base.IsTextFile(buf)
83 82
 		ctx.Data["FileIsText"] = isTextFile
@@ -134,9 +133,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
134 133
 
135 134
 	buf := make([]byte, 1024)
136 135
 	n, _ := dataRc.Read(buf)
137
-	if n > 0 {
138
-		buf = buf[:n]
139
-	}
136
+	buf = buf[:n]
140 137
 
141 138
 	isTextFile := base.IsTextFile(buf)
142 139
 	ctx.Data["IsTextFile"] = isTextFile

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
1
-0.9.97.0830
1
+0.9.97.0831