(file: File)
| 171 | }; |
| 172 | |
| 173 | export const sanitizeSvg = async (file: File): Promise<File> => { |
| 174 | try { |
| 175 | const text = await file.text(); |
| 176 | const cleanSvg = DOMPurify.sanitize(text, { |
| 177 | USE_PROFILES: {svg: true}, |
| 178 | ADD_TAGS: ['use'], |
| 179 | }); |
| 180 | return new File([cleanSvg], file.name, {type: 'image/svg+xml'}); |
| 181 | } catch (e) { |
| 182 | console.warn( |
| 183 | 'SVG Sanitization failed, returning original (risky but fallback)', |
| 184 | e, |
| 185 | ); |
| 186 | return file; |
| 187 | } |
| 188 | }; |
| 189 | |
| 190 | export const validateAndSanitizeFile = async ( |
| 191 | file: File, |
no outgoing calls
no test coverage detected