Skip to content

Commit 5b3912f

Browse files
committed
refactor: remove unnecessary Element check
[DOMPurify v3.2.2][1] narrowed down the types of these hooks so that these are known to have the `Element` type, which means checking the type of these at runtime is unnecessary. [1]: https://github.com/cure53/DOMPurify/releases/tag/3.2.2 See: fe3cffb See: cure53/DOMPurify@4cdfd1f Cherry-picked-from: 7a1530d
1 parent 01ff8c5 commit 5b3912f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • packages/mermaid/src/diagrams/common

packages/mermaid/src/diagrams/common/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ function setupDompurifyHooks() {
3333
const TEMPORARY_ATTRIBUTE = 'data-temp-href-target';
3434

3535
DOMPurify.addHook('beforeSanitizeAttributes', (node) => {
36-
if (node instanceof Element && node.tagName === 'A' && node.hasAttribute('target')) {
36+
if (node.tagName === 'A' && node.hasAttribute('target')) {
3737
node.setAttribute(TEMPORARY_ATTRIBUTE, node.getAttribute('target') ?? '');
3838
}
3939
});
4040

4141
DOMPurify.addHook('afterSanitizeAttributes', (node) => {
42-
if (node instanceof Element && node.tagName === 'A' && node.hasAttribute(TEMPORARY_ATTRIBUTE)) {
42+
if (node.tagName === 'A' && node.hasAttribute(TEMPORARY_ATTRIBUTE)) {
4343
node.setAttribute('target', node.getAttribute(TEMPORARY_ATTRIBUTE) ?? '');
4444
node.removeAttribute(TEMPORARY_ATTRIBUTE);
4545
if (node.getAttribute('target') === '_blank') {

0 commit comments

Comments
 (0)