Skip to content

Commit f4e677e

Browse files
authored
Fix bug on avatar middleware (#15124)
1 parent 687e2df commit f4e677e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

routers/routes/base.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"os"
1313
"path"
14+
"path/filepath"
1415
"strings"
1516
"time"
1617

@@ -87,13 +88,21 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
8788
return
8889
}
8990

90-
if !strings.HasPrefix(req.URL.RequestURI(), "/"+prefix) {
91+
prefix := strings.Trim(prefix, "/")
92+
93+
if !strings.HasPrefix(req.URL.EscapedPath(), "/"+prefix+"/") {
9194
next.ServeHTTP(w, req)
9295
return
9396
}
9497

95-
rPath := strings.TrimPrefix(req.URL.RequestURI(), "/"+prefix)
98+
rPath := strings.TrimPrefix(req.URL.EscapedPath(), "/"+prefix+"/")
9699
rPath = strings.TrimPrefix(rPath, "/")
100+
if rPath == "" {
101+
http.Error(w, "file not found", 404)
102+
return
103+
}
104+
rPath = path.Clean("/" + filepath.ToSlash(rPath))
105+
rPath = rPath[1:]
97106

98107
fi, err := objStore.Stat(rPath)
99108
if err == nil && httpcache.HandleTimeCache(req, w, fi) {

0 commit comments

Comments
 (0)