Skip to content

Commit 151beda

Browse files
6543lunny
andauthored
Fix bug on avatar middleware (#15125)
Co-authored-by: Lunny Xiao <[email protected]>
1 parent 6198403 commit 151beda

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

routers/routes/routes.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"net/http"
1414
"os"
1515
"path"
16+
"path/filepath"
1617
"strings"
1718
"text/template"
1819
"time"
@@ -152,12 +153,21 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
152153
return
153154
}
154155

155-
if !strings.HasPrefix(req.URL.RequestURI(), "/"+prefix) {
156+
prefix := strings.Trim(prefix, "/")
157+
158+
if !strings.HasPrefix(req.URL.EscapedPath(), "/"+prefix+"/") {
156159
return
157160
}
161+
rPath := strings.TrimPrefix(req.URL.EscapedPath(), "/"+prefix+"/")
158162

159-
rPath := strings.TrimPrefix(req.URL.RequestURI(), "/"+prefix)
160163
rPath = strings.TrimPrefix(rPath, "/")
164+
if rPath == "" {
165+
ctx.Error(404, "file not found")
166+
return
167+
}
168+
rPath = path.Clean("/" + filepath.ToSlash(rPath))
169+
rPath = rPath[1:]
170+
161171
//If we have matched and access to release or issue
162172
fr, err := objStore.Open(rPath)
163173
if err != nil {

0 commit comments

Comments
 (0)