diff options
Diffstat (limited to 'misc/path.go')
-rw-r--r-- | misc/path.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/misc/path.go b/misc/path.go new file mode 100644 index 0000000..c7013d8 --- /dev/null +++ b/misc/path.go @@ -0,0 +1,27 @@ +package misc + +import ( + "path/filepath" + "strings" +) + +func sanitize_path(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 +} |