fix: use PathUnescape for filename URL decoding (#1214)

This commit is contained in:
Copilot authored and GitHub committed 2026-01-05 21:46:50 +08:00
1 parent 71c9e6947a
commit 6756d82ffa
5 files changed
+98 -6

No files matched your search

+13
View File
@@ -66,3 +66,16 @@ func TryUrlQueryUnescape(s string) string {
}
return s
}
// TryUrlPathUnescape tries to unescape a URL path-encoded string.
// Unlike QueryUnescape, PathUnescape does not treat '+' as a space.
// This is the correct function to use for decoding URL paths and filenames
// where %2B should decode to '+', not to a space.
//
// If unescaping fails, it returns the original string.
func TryUrlPathUnescape(s string) string {
if decoded, err := url.PathUnescape(s); err == nil {
return decoded
}
return s
}