fix: added type Element to the node used in callback in the dompurify.addhook

This commit is contained in:
Harshit Anand
2023-10-23 12:23:08 +05:30
parent 345e82abee
commit 3b8c48dd26

View File

@@ -30,13 +30,13 @@ export const removeScript = (txt: string): string => {
const TEMPORARY_ATTRIBUTE = 'data-temp-href-target';
DOMPurify.addHook('beforeSanitizeAttributes', function (node) {
DOMPurify.addHook('beforeSanitizeAttributes', (node: Element) => {
if (node.tagName === 'A' && node.hasAttribute('target')) {
node.setAttribute(TEMPORARY_ATTRIBUTE, node.getAttribute('target') || '');
}
});
DOMPurify.addHook('afterSanitizeAttributes', function (node) {
DOMPurify.addHook('afterSanitizeAttributes', (node: Element) => {
if (node.tagName === 'A' && node.hasAttribute(TEMPORARY_ATTRIBUTE)) {
node.setAttribute('target', node.getAttribute(TEMPORARY_ATTRIBUTE) || '');
node.removeAttribute(TEMPORARY_ATTRIBUTE);