From 00a6e9258a7988de9c6cc8cfb6a690ce7f377755 Mon Sep 17 00:00:00 2001 From: mturoci <64769322+mturoci@users.noreply.github.com> Date: Wed, 3 Aug 2022 09:07:50 +0200 Subject: [PATCH] fix: Account for baseURL when deleting files (site.unload). #1557 (#1558) --- file_server.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/file_server.go b/file_server.go index df04e5bf24..e7ae3650cc 100644 --- a/file_server.go +++ b/file_server.go @@ -110,8 +110,9 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - if err := fs.deleteFile(r.URL.Path); err != nil { + if err := fs.deleteFile(r.URL.Path, fs.baseURL); err != nil { echo(Log{"t": "file_unload", "path": r.URL.Path, "error": err.Error()}) + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } echo(Log{"t": "file_unload", "path": r.URL.Path}) @@ -172,8 +173,10 @@ func (fs *FileServer) acceptFiles(r *http.Request) ([]string, error) { return uploadPaths, nil } -func (fs *FileServer) deleteFile(url string) error { - tokens := strings.Split(path.Clean(url), "/") +func (fs *FileServer) deleteFile(url, baseURL string) error { + // Remove baseURL portion if specified. + cleanURL := strings.Replace(path.Clean(url), baseURL, "/_f", 1) + tokens := strings.Split(cleanURL, "/") if len(tokens) != 4 { // /_f/uuid/file.ext return errInvalidUnloadPath }