mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-08 09:30:27 +00:00
fix: use PathUnescape for filename URL decoding (#1214)
This commit is contained in:
1 parent
71c9e6947a
commit
6756d82ffa
5 files changed
+98
-6
No files matched your search
@@ -171,9 +171,9 @@ 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
|
||||
// Url decode - use PathUnescape for paths to handle %2B correctly
|
||||
if file.Name != "" {
|
||||
file.Name, _ = url.QueryUnescape(file.Name)
|
||||
file.Name, _ = url.PathUnescape(file.Name)
|
||||
}
|
||||
}
|
||||
// unknown file filePath
|
||||
@@ -656,7 +656,8 @@ func parseFilenameExtended(cd string) string {
|
||||
if len(parts) == 2 {
|
||||
// parts[0] is charset (e.g., "UTF-8")
|
||||
// parts[1] is percent-encoded value
|
||||
decoded, err := url.QueryUnescape(parts[1])
|
||||
// Use PathUnescape to handle %2B correctly (should decode to +, not space)
|
||||
decoded, err := url.PathUnescape(parts[1])
|
||||
if err == nil {
|
||||
return decoded
|
||||
}
|
||||
@@ -665,7 +666,8 @@ func parseFilenameExtended(cd string) string {
|
||||
// Try with single quote delimiter as well (some servers use this)
|
||||
parts = strings.SplitN(value, "'", 3)
|
||||
if len(parts) >= 3 {
|
||||
decoded, err := url.QueryUnescape(parts[2])
|
||||
// Use PathUnescape to handle %2B correctly (should decode to +, not space)
|
||||
decoded, err := url.PathUnescape(parts[2])
|
||||
if err == nil {
|
||||
return decoded
|
||||
}
|
||||
@@ -687,8 +689,8 @@ func decodeFilenameParam(filename string) string {
|
||||
}
|
||||
}
|
||||
|
||||
// Try URL decoding
|
||||
decoded := util.TryUrlQueryUnescape(filename)
|
||||
// Try URL decoding - use PathUnescape for filenames to handle %2B correctly
|
||||
decoded := util.TryUrlPathUnescape(filename)
|
||||
|
||||
// Check if the result is valid UTF-8. If not, try GBK decoding.
|
||||
// This handles the case where Chinese Windows servers send GBK-encoded filenames
|
||||
|
||||
Reference in new issue
Block a user