Lindenii Project Forge
Warning: Due to various recent migrations, viewing non-HEAD refs may be broken.
/misc/path.go (raw)
package misc
import (
"path/filepath"
"strings"
)
func SanitizePath(path string) (string, bool) {
if path == "" {
return "", false
}
path = strings.TrimLeft(path, "/")
for _, part := range strings.Split(path, "/") {
if part == "." || part == ".." {
path = filepath.Clean(path)
break
}
}
if path == ".." || strings.HasPrefix(path, "../") {
return "", false
}
return path, true
}