From 84bc9ac583167c1ce80881e9bf56132baf36642f Mon Sep 17 00:00:00 2001 From: moecinnamo Date: Thu, 11 Sep 2025 20:20:45 +0800 Subject: [PATCH] Resolve the issue of returning a 404 if the file name contains a+instead of a space. --- file.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/file.go b/file.go index d363a19..fcf2d0e 100644 --- a/file.go +++ b/file.go @@ -148,11 +148,22 @@ func fileHandler(w http.ResponseWriter, r *http.Request) { // Construct the complete file path fullFilePath := filepath.Join("./files", filePath) + // Try replacing '+' with ' ' and check if the file exists + tempFilePath := strings.ReplaceAll(fullFilePath, "+", " ") + if _, err := os.Stat(tempFilePath); err == nil { + fullFilePath = tempFilePath + } + // Get file content fileContent, err := GetFileContent(fullFilePath) if err != nil { - NotFoundHandler(w, r) - return + // If file not found, try replacing ' ' with '+' and check again + tempFilePath = strings.ReplaceAll(fullFilePath, " ", "+") + fileContent, err = GetFileContent(tempFilePath) + if err != nil { + NotFoundHandler(w, r) + return + } } // Set appropriate Content-Type based on file extension