FeedReader: Be safe when calling createDocumentFragment()

Addresses #4733
This commit is contained in:
Abe Jellinek 2024-10-07 17:05:21 -04:00
parent fa2316154e
commit f1aeb278a6

View file

@ -412,10 +412,12 @@ Zotero.FeedReader._getFeedItem = function (feedEntry, feedInfo) {
if (feedEntry.content || feedEntry.summary) {
let abstractFragment = (feedEntry.content || feedEntry.summary).createDocumentFragment();
if (abstractFragment.querySelectorAll('body').length === 1) {
abstractFragment.replaceChildren(...abstractFragment.querySelector('body').childNodes);
if (abstractFragment) {
if (abstractFragment.querySelectorAll('body').length === 1) {
abstractFragment.replaceChildren(...abstractFragment.querySelector('body').childNodes);
}
item.abstractNote = new XMLSerializer().serializeToString(abstractFragment);
}
item.abstractNote = new XMLSerializer().serializeToString(abstractFragment);
}
if (feedEntry.summary && !item.title) {
@ -531,6 +533,9 @@ Zotero.FeedReader._getRichText = function (feedText, field) {
return feedText;
}
let domFragment = feedText.createDocumentFragment();
if (!domFragment) {
return '';
}
return Zotero.Utilities.trimInternal(domFragment.textContent);
};