(escaped: string)
| 73 | } |
| 74 | |
| 75 | export function unescape(escaped: string) { |
| 76 | return escaped.replace(/\\([\dA-Fa-f]{1,6}[\t\n\f\r ]?|[\S\s])/g, (match) => { |
| 77 | if (match.length <= 2) { |
| 78 | return match[1] |
| 79 | } |
| 80 | |
| 81 | let codePoint = Number.parseInt(match.slice(1).trim(), 16) |
| 82 | |
| 83 | if ( |
| 84 | // Invalid codepoint: https://infra.spec.whatwg.org/#code-point |
| 85 | codePoint === 0x0000 || |
| 86 | codePoint > 0x10ffff || |
| 87 | // Is surrogate: https://infra.spec.whatwg.org/#leading-surrogate |
| 88 | // - A leading surrogate is a code point that is in the range U+D800 to U+DBFF, inclusive. |
| 89 | // - A trailing surrogate is a code point that is in the range U+DC00 to U+DFFF, inclusive. |
| 90 | (codePoint >= 0xd800 && codePoint <= 0xdfff) |
| 91 | ) { |
| 92 | return '\uFFFD' |
| 93 | } |
| 94 | |
| 95 | return String.fromCodePoint(codePoint) |
| 96 | }) |
| 97 | } |
no outgoing calls
no test coverage detected