apostrophecms / sanitize-html

Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis. Built on htmlparser2 for speed and tolerance

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XHTML <br></br> converted to <br /><br />

eumpek opened this issue · comments

To Reproduce

Step by step instructions to reproduce the behavior:
const sanitizeHtml = require('sanitize-html'); let html = '<br></br>'; sanitizeHtml(html, {allowedTags: ['br']});

Expected behavior

The <br></br> is a single XHTML line break which is expected to be converted to <br />.

Describe the bug

The library doesn't consider the case of the <br></br> as line break and converts it to double line break which is totally unexpected.

Details

Version of Node.js:
12.16.1

Screenshots
Screenshot 2021-05-20 at 14 36 22

In the default options section of the README one of the options set is selfClosingTags. You could set that option to the same array minus br to treat that as a normal tag. Presumably you are using the output as XHTML, so you don't need it converted to a single self-closing break tag.