Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit dadd35b

Browse files
committed
#3559 fix template error
1 parent c2afdf2 commit dadd35b

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/gogits/gogs/modules/setting"
1818
)
1919

20-
const APP_VER = "0.9.97.0830"
20+
const APP_VER = "0.9.97.0831"
2121

2222
func init() {
2323
runtime.GOMAXPROCS(runtime.NumCPU())

modules/base/tool.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,11 @@ func IsLetter(ch rune) bool {
518518
return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= 0x80 && unicode.IsLetter(ch)
519519
}
520520

521+
// IsTextFile returns true if file content format is plain text or empty.
521522
func IsTextFile(data []byte) bool {
523+
if len(data) == 0 {
524+
return true
525+
}
522526
return strings.Index(http.DetectContentType(data), "text/") != -1
523527
}
524528

routers/repo/editor.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
6464

6565
buf := make([]byte, 1024)
6666
n, _ := dataRc.Read(buf)
67-
if n > 0 {
68-
buf = buf[:n]
69-
}
67+
buf = buf[:n]
7068

7169
// Only text file are editable online.
7270
if !base.IsTextFile(buf) {

routers/repo/view.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
6464
}
6565

6666
if readmeFile != nil {
67+
ctx.Data["RawFileLink"] = ""
6768
ctx.Data["ReadmeInList"] = true
6869
ctx.Data["ReadmeExist"] = true
6970

@@ -75,9 +76,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
7576

7677
buf := make([]byte, 1024)
7778
n, _ := dataRc.Read(buf)
78-
if n > 0 {
79-
buf = buf[:n]
80-
}
79+
buf = buf[:n]
8180

8281
isTextFile := base.IsTextFile(buf)
8382
ctx.Data["FileIsText"] = isTextFile
@@ -134,9 +133,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
134133

135134
buf := make([]byte, 1024)
136135
n, _ := dataRc.Read(buf)
137-
if n > 0 {
138-
buf = buf[:n]
139-
}
136+
buf = buf[:n]
140137

141138
isTextFile := base.IsTextFile(buf)
142139
ctx.Data["IsTextFile"] = isTextFile

templates/.VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.97.0830
1+
0.9.97.0831

0 commit comments

Comments
 (0)