HtmlSanitizer icon indicating copy to clipboard operation
HtmlSanitizer copied to clipboard

Error whenn _tagWhitelist missing BODY

Open markusweb opened this issue 1 year ago • 1 comments

i want to have a very restrictive tag list

const _tagWhitelist = { 'A': true, 'B': true, 'BODY': true, 'BR': true, };

but if i remove 'BODY': true, i get an javascript error in console saying

Uncaught TypeError: resultElement.innerHTML is undefined

markusweb avatar Jun 15 '23 10:06 markusweb

Maybe a workaround: put body in the content tag white list. (list of tags to replace with DIVs)

This code, in a middle step, turns the input HTML string into a little mini-document with to-be-filtered DOM in its body, even if your HTML string didn't have a body. So when you ask it to ignore body elements, it basically ignores everything.

(Disclaimer: I didn't actually try this workaround; I was doing enough weird stuff such that I ended up writing new code inspired by this. I remember that I needed to handle bodies specially, though)

lahosken avatar Oct 07 '23 16:10 lahosken