mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-25 13:39:22 +00:00
handle invalid feeds
This commit is contained in:
parent
da0626df4e
commit
996bcdc90d
@ -22,6 +22,9 @@ var debounce = function(callback, wait) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var sanitize = function(content, base) {
|
var sanitize = function(content, base) {
|
||||||
|
// NOTE: `item.link` is not always a valid url
|
||||||
|
try { new URL(base) } catch(err) { base = null }
|
||||||
|
|
||||||
var sanitizer = new DOMPurify
|
var sanitizer = new DOMPurify
|
||||||
sanitizer.addHook('afterSanitizeAttributes', function(node) {
|
sanitizer.addHook('afterSanitizeAttributes', function(node) {
|
||||||
// set all elements owning target to target=_blank
|
// set all elements owning target to target=_blank
|
||||||
@ -32,9 +35,9 @@ var sanitize = function(content, base) {
|
|||||||
node.setAttribute('xlink:show', 'new')
|
node.setAttribute('xlink:show', 'new')
|
||||||
|
|
||||||
// set absolute urls
|
// set absolute urls
|
||||||
if (node.attributes.href && node.attributes.href.value)
|
if (base && node.attributes.href && node.attributes.href.value)
|
||||||
node.href = new URL(node.attributes.href.value, base).toString()
|
node.href = new URL(node.attributes.href.value, base).toString()
|
||||||
if (node.attributes.src && node.attributes.src.value)
|
if (base && node.attributes.src && node.attributes.src.value)
|
||||||
node.src = new URL(node.attributes.src.value, base).toString()
|
node.src = new URL(node.attributes.src.value, base).toString()
|
||||||
})
|
})
|
||||||
return sanitizer.sanitize(content, {FORBID_TAGS: ['style'], FORBID_ATTR: ['style', 'class']})
|
return sanitizer.sanitize(content, {FORBID_TAGS: ['style'], FORBID_ATTR: ['style', 'class']})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user