refactor(webdav): Use ResolvePath instead of JoinPath (#9344)

- Changed the path concatenation method between `reqPath` and `src` and `dst` to use `ResolvePath`
- Updated the implementation of path handling in multiple functions
- Improved the consistency and reliability of path resolution
This commit is contained in:
千石
2025-10-16 02:23:11 -07:00
committed by GitHub
parent a6bd90a9b2
commit e2016dd031
3 changed files with 33 additions and 11 deletions

22
server/webdav/path.go Normal file
View File

@@ -0,0 +1,22 @@
package webdav
import (
"path"
"strings"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils"
)
// ResolvePath normalizes the provided raw path and resolves it against the user's base path
// before delegating to the user-aware JoinPath permission checks.
func ResolvePath(user *model.User, raw string) (string, error) {
cleaned := utils.FixAndCleanPath(raw)
basePath := utils.FixAndCleanPath(user.BasePath)
if cleaned != "/" && basePath != "/" && !utils.IsSubPath(basePath, cleaned) {
cleaned = path.Join(basePath, strings.TrimPrefix(cleaned, "/"))
}
return user.JoinPath(cleaned)
}