| 1 | |
| 2 | export function terminalClipboardText(data) { |
| 3 | const separator = data.indexOf(";"); |
| 4 | if (separator < 0 || !["", "c"].includes(data.slice(0, separator))) return; |
| 5 | const encoded = data.slice(separator + 1); |
| 6 | if (encoded === "?" || encoded.length > 4 * Math.ceil((2 * 1024 * 1024) / 3) || |
| 7 | encoded.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(encoded)) return; |
| 8 | try { |
| 9 | const bytes = Uint8Array.from(atob(encoded), character => character.charCodeAt(0)); |
| 10 | if (bytes.length > 2 * 1024 * 1024) return; |
| 11 | return new TextDecoder("utf-8", { fatal: true }).decode(bytes); |
| 12 | } catch { } |
| 13 | } |