fix: path url encode filename parse (#939)

This commit is contained in:
Levi authored and GitHub committed 2025-02-18 19:37:38 +08:00
1 parent a094715d69
commit 9c5aebaf36
3 files changed
+22

No files matched your search

+4
View File
@@ -160,6 +160,10 @@ func (f *Fetcher) Resolve(req *base.Request) error {
// get file filePath by URL
if file.Name == "" {
file.Name = path.Base(httpReq.URL.Path)
// Url decode
if file.Name != "" {
file.Name, _ = url.QueryUnescape(file.Name)
}
}
// unknown file filePath
if file.Name == "" || file.Name == "/" || file.Name == "." {
+10
View File
@@ -47,6 +47,16 @@ func TestFetcher_Resolve(t *testing.T) {
},
},
}, t)
testResolve(test.StartTestCustomServer, "%E6%B5%8B%E8%AF%95.zip", &base.Resource{
Size: 0,
Range: false,
Files: []*base.FileInfo{
{
Name: "测试.zip",
Size: 0,
},
},
}, t)
testResolve(test.StartTestCustomServer, test.BuildName, &base.Resource{
Size: 0,
Range: false,
+8
View File
@@ -94,6 +94,14 @@ func StartTestCustomServer() net.Listener {
defer file.Close()
io.Copy(writer, file)
})
mux.HandleFunc("/%E6%B5%8B%E8%AF%95.zip", func(writer http.ResponseWriter, request *http.Request) {
file, err := os.Open(BuildFile)
if err != nil {
panic(err)
}
defer file.Close()
io.Copy(writer, file)
})
return mux
})
}