Fix #126
This commit is contained in:
parent
5b5581392d
commit
c7f702cd15
|
@ -122,19 +122,13 @@ func GetFile(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isBinary := false
|
content := string(buf)
|
||||||
// determine whether it is a binary file
|
|
||||||
for _, b := range buf {
|
|
||||||
if 0 == b {
|
|
||||||
isBinary = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if isBinary {
|
if isBinary(content) {
|
||||||
data["succ"] = false
|
data["succ"] = false
|
||||||
data["msg"] = "Can't open a binary file :("
|
data["msg"] = "Can't open a binary file :("
|
||||||
} else {
|
} else {
|
||||||
data["content"] = string(buf)
|
data["content"] = content
|
||||||
data["mode"] = getEditorMode(extension)
|
data["mode"] = getEditorMode(extension)
|
||||||
data["path"] = path
|
data["path"] = path
|
||||||
}
|
}
|
||||||
|
@ -491,6 +485,10 @@ func searchInFile(path string, text string) []*Snippet {
|
||||||
}
|
}
|
||||||
|
|
||||||
content := string(bytes)
|
content := string(bytes)
|
||||||
|
if isBinary(content) {
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
lines := strings.Split(content, "\n")
|
lines := strings.Split(content, "\n")
|
||||||
|
|
||||||
for idx, line := range lines {
|
for idx, line := range lines {
|
||||||
|
@ -506,6 +504,17 @@ func searchInFile(path string, text string) []*Snippet {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isBinary determines whether the specified content is a binary file content.
|
||||||
|
func isBinary(content string) bool {
|
||||||
|
for _, b := range content {
|
||||||
|
if 0 == b {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// isImg determines whether the specified extension is a image.
|
// isImg determines whether the specified extension is a image.
|
||||||
func isImg(extension string) bool {
|
func isImg(extension string) bool {
|
||||||
ext := strings.ToLower(extension)
|
ext := strings.ToLower(extension)
|
||||||
|
|
Loading…
Reference in New Issue