Big emojis: fix possible web crash

error-boundary-browser-info
Alex Gleason 2021-07-10 12:41:57 -05:00
rodzic f208d350a2
commit a66f2b3f75
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 19 dodań i 12 usunięć

Wyświetl plik

@ -2,6 +2,7 @@
export const onlyEmoji = (node, limit = 1, ignoreMentions = true) => {
if (!node) return false;
try {
// Remove mentions before checking content
if (ignoreMentions) {
node = node.cloneNode(true);
@ -15,4 +16,10 @@ export const onlyEmoji = (node, limit = 1, ignoreMentions = true) => {
const images = Array.from(node.querySelectorAll('img'));
if (images.length > emojis.length) return false;
return true;
} catch (e) {
// Apparently some browsers can't handle `node.textContent.replaceAll`??
// If anything in here crashes, skipping it is inconsequential.
console.error(e);
return false;
}
};