mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-06-20 04:14:18 +00:00
Fix: preserve non-ASCII filenames in document downloads (#9702)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
export function getFilenameFromContentDisposition(header: string): string {
|
||||
if (!header) {
|
||||
return null
|
||||
}
|
||||
|
||||
// Try filename* (RFC 5987)
|
||||
const filenameStar = header.match(/filename\*=(?:UTF-\d['']*)?([^;]+)/i)
|
||||
if (filenameStar?.[1]) {
|
||||
try {
|
||||
return decodeURIComponent(filenameStar[1])
|
||||
} catch (e) {
|
||||
// Ignore decoding errors and fall through
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to filename=
|
||||
const filenameMatch = header.match(/filename="?([^"]+)"?/)
|
||||
if (filenameMatch?.[1]) {
|
||||
return filenameMatch[1]
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user