feat: some updates
This commit is contained in:
@@ -12,7 +12,7 @@ func CleanURLLike(p string) string {
|
||||
return "/"
|
||||
}
|
||||
parts := []string{}
|
||||
for _, seg := range strings.Split(strings.ReplaceAll(p, "\\", "/"), "/") {
|
||||
for seg := range strings.SplitSeq(strings.ReplaceAll(p, "/", "/"), "/") {
|
||||
switch seg {
|
||||
case "", ".":
|
||||
continue
|
||||
@@ -29,8 +29,8 @@ func CleanURLLike(p string) string {
|
||||
|
||||
func SafeRel(root, requested string) (string, error) {
|
||||
s := CleanURLLike(requested)
|
||||
if strings.HasPrefix(s, "/") {
|
||||
s = strings.TrimPrefix(s, "/")
|
||||
if after, ok := strings.CutPrefix(s, "/"); ok {
|
||||
s = after
|
||||
}
|
||||
full := filepath.Join(root, filepath.FromSlash(s))
|
||||
rel, err := filepath.Rel(root, full)
|
||||
|
Reference in New Issue
Block a user