(input: string)
| 48 | } |
| 49 | |
| 50 | export function escapeCssUrl(input: string): string { |
| 51 | return ( |
| 52 | input |
| 53 | // Backslash first — later replacements must not have their own \ escaped again. |
| 54 | .replace(/\\/g, '\\\\') |
| 55 | // \n, \r, \f and null terminate a CSS string (CSS Syntax 3 §4.3.5, |
| 56 | // https://www.w3.org/TR/css-syntax-3/#consume-string-token) and are also |
| 57 | // invalid in URLs, so stripping them is safe. |
| 58 | .replace(/[\n\r\f\0]/g, '') |
| 59 | // A bare " would close the url("...") wrapper early. |
| 60 | .replace(/"/g, '\\"') |
| 61 | ); |
| 62 | } |
no test coverage detected