Skip to content

Commit

Permalink
fix: error guard for edge svg attr bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kyuwoo.choi committed Dec 29, 2017
1 parent cf9ddf5 commit c2e0300
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/js/htmlSanitizer.js
Expand Up @@ -64,15 +64,20 @@ function removeUnnecessaryTags($html) {
*/
function leaveOnlyWhitelistAttribute($html) {
$html.find('*').each((index, node) => {
const blacklist = util.toArray(node.attributes).filter(attr => {
const attrs = node.attributes;
const blacklist = util.toArray(attrs).filter(attr => {
const isHTMLAttr = attr.name.match(HTML_ATTR_LIST_RX);
const isSVGAttr = attr.name.match(SVG_ATTR_LIST_RX);

return !isHTMLAttr && !isSVGAttr;
});

util.forEachArray(blacklist, attr => {
node.attributes.removeNamedItem(attr.name);
// Edge svg attribute name returns uppercase bug. error guard.
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/5579311/
if (attrs.getNamedItem(attr.name)) {
attrs.removeNamedItem(attr.name);
}
});
});
}
Expand Down

0 comments on commit c2e0300

Please sign in to comment.