From cbbcb71b8856d095f425ec5b3fe15ef974b4db59 Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Sat, 4 Nov 2023 15:12:19 +0000 Subject: [PATCH] fix: remove hrefs for unconventional namespaces --- plugins/removeScriptElement.js | 32 +++++++++++++------------ test/plugins/removeScriptElement.05.svg | 19 +++++++++++++++ 2 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 test/plugins/removeScriptElement.05.svg diff --git a/plugins/removeScriptElement.js b/plugins/removeScriptElement.js index eb1a6ba54..80fcea3b6 100644 --- a/plugins/removeScriptElement.js +++ b/plugins/removeScriptElement.js @@ -43,23 +43,25 @@ exports.fn = () => { return; } - for (const attr of ['href', 'xlink:href']) { - if ( - node.attributes[attr] == null || - !node.attributes[attr].trimStart().startsWith('javascript:') - ) { - continue; - } + for (const attr of Object.keys(node.attributes)) { + if (attr === 'href' || attr.endsWith(':href')) { + if ( + node.attributes[attr] == null || + !node.attributes[attr].trimStart().startsWith('javascript:') + ) { + continue; + } - const index = parentNode.children.indexOf(node); - parentNode.children.splice(index, 1, ...node.children); + const index = parentNode.children.indexOf(node); + parentNode.children.splice(index, 1, ...node.children); - // TODO remove legacy parentNode in v4 - for (const child of node.children) { - Object.defineProperty(child, 'parentNode', { - writable: true, - value: parentNode, - }); + // TODO remove legacy parentNode in v4 + for (const child of node.children) { + Object.defineProperty(child, 'parentNode', { + writable: true, + value: parentNode, + }); + } } } }, diff --git a/test/plugins/removeScriptElement.05.svg b/test/plugins/removeScriptElement.05.svg new file mode 100644 index 000000000..066498d62 --- /dev/null +++ b/test/plugins/removeScriptElement.05.svg @@ -0,0 +1,19 @@ +Removes hrefs to JavaScript URIs, including unconventional namespaces. + +=== + + + + uwu + + + uwu + + + +@@@ + + + uwu + uwu +