mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-14 00:48:26 +08:00
refactor: use slices.Contains to simplify code (#16680)
### Summary There is a [new function](https://pkg.go.dev/slices@go1.21.0#Contains) added in the go1.21 standard library, which can make the code more concise and easy to read. Signed-off-by: weifanglab <weifanglab@outlook.com>
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -905,24 +906,13 @@ func isSafePath(path string) bool {
|
||||
|
||||
// Check for parent directory references
|
||||
parts := strings.Split(clean, string(filepath.Separator))
|
||||
for _, part := range parts {
|
||||
if part == ".." {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
return !slices.Contains(parts, "..")
|
||||
}
|
||||
|
||||
// isTextContent checks if content appears to be text (not binary)
|
||||
func isTextContent(data []byte) bool {
|
||||
// Check for null bytes (indicates binary)
|
||||
for _, b := range data {
|
||||
if b == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return !slices.Contains(data, 0)
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
|
||||
Reference in New Issue
Block a user