( metadata: Record<string, string>, maxLength: number )
| 828 | * @returns Sanitized metadata object |
| 829 | */ |
| 830 | export function sanitizeStorageMetadata( |
| 831 | metadata: Record<string, string>, |
| 832 | maxLength: number |
| 833 | ): Record<string, string> { |
| 834 | const sanitized: Record<string, string> = {} |
| 835 | for (const [key, value] of Object.entries(metadata)) { |
| 836 | const sanitizedValue = String(value) |
| 837 | .replace(/[^\x20-\x7E]/g, '') |
| 838 | .replace(/["\\]/g, '') |
| 839 | .substring(0, maxLength) |
| 840 | if (sanitizedValue) { |
| 841 | sanitized[key] = sanitizedValue |
| 842 | } |
| 843 | } |
| 844 | return sanitized |
| 845 | } |
| 846 | |
| 847 | /** |
| 848 | * Sanitize a file key/path for local storage |
no test coverage detected