# HG changeset patch # User Guido Berhoerster # Date 1544456291 -3600 # Node ID 376a0e415bbac79f4d2d0ceb08080c476e718be0 # Parent 799d633ccd4d7b72d269914200c7ead894b50225 Properly handle non-text content in Atom feed elements The title, subtitle, summary and content elements of Atom feeds can all have non-text content. When parsing title and subtitle elements HTML and XHTML content will be stripped of any markup in order to keep it simple. In summary and content elements markup will be preserved. Element content of any other type as well as remote content in content elements will be ignored. diff -r 799d633ccd4d -r 376a0e415bba js/background.js --- a/js/background.js Sat Dec 08 12:12:18 2018 +0100 +++ b/js/background.js Mon Dec 10 16:38:11 2018 +0100 @@ -48,7 +48,10 @@ const FEED_MAGIC = [ '${encodeXML(text)}`; + } + + // unsupported content type + return; + } + + parseAtomContent(contentElement) { + let contentSrc = contentElement.getAttribute('src'); + if (contentSrc !== null) { + // externally referenced content is not supported + return; + } + return this.parseAtomTextConstruct(contentElement, false); + } + parseAtomEntry(entryElement) { let title; let link; @@ -224,7 +265,7 @@ let titleElement = feedQueryXPath(this.document, entryElement, './atom:title'); if (titleElement !== null) { - title = titleElement.textContent.trim(); + title = this.parseAtomTextConstruct(titleElement); } let linkElement = feedQueryXPath(this.document, entryElement, @@ -241,24 +282,14 @@ let contentElement = feedQueryXPath(this.document, entryElement, './atom:content'); - if (contentElement === null) { - contentElement = feedQueryXPath(this.document, entryElement, - './atom:summary'); + if (contentElement !== null) { + content = this.parseAtomContent(contentElement); } - if (contentElement !== null) { - let contentType = contentElement.getAttribute('type'); - if (contentType === null) { - contentType = 'text'; - } - contentType = contentType.toLowerCase(); - if (contentType === 'xhtml') { - content = contentElement.innerHTML; - } else if (contentType === 'html') { - content = contentElement.textContent; - } else { - let encodedContent = - encodeXML(contentElement.textContent.trim()); - content = `
${encodedContent}
`; + if (typeof content === 'undefined') { + let summaryElement = feedQueryXPath(this.document, entryElement, + './atom:summary'); + if (summaryElement !== null) { + content = this.parseAtomTextConstruct(summaryElement, false); } } @@ -275,13 +306,13 @@ let titleElement = feedQueryXPath(this.document, documentElement, './atom:title'); if (titleElement !== null) { - title = titleElement.textContent.trim(); + title = this.parseAtomTextConstruct(titleElement); } let subtitleElement = feedQueryXPath(this.document, documentElement, './atom:subtitle'); if (subtitleElement !== null) { - subtitle = subtitleElement.textContent.trim(); + subtitle = this.parseAtomTextConstruct(subtitleElement); } let logoElement = feedQueryXPath(this.document, documentElement,