(filename: string)
| 805 | * and cannot contain certain special characters |
| 806 | */ |
| 807 | export function sanitizeFilenameForMetadata(filename: string): string { |
| 808 | return ( |
| 809 | filename |
| 810 | // Remove non-ASCII characters (keep only printable ASCII 0x20-0x7E) |
| 811 | .replace(/[^\x20-\x7E]/g, '') |
| 812 | // Remove characters that are problematic in HTTP headers |
| 813 | .replace(/["\\]/g, '') |
| 814 | // Replace multiple spaces with single space |
| 815 | .replace(/\s+/g, ' ') |
| 816 | // Trim whitespace |
| 817 | .trim() || |
| 818 | // Provide fallback if completely sanitized |
| 819 | 'file' |
| 820 | ) |
| 821 | } |
| 822 | |
| 823 | /** |
| 824 | * Sanitize metadata values for storage providers |
no test coverage detected