Skip to content

Commit

Permalink
fix: remove hrefs for unconventional namespaces (#1820)
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed Nov 4, 2023
1 parent e21e560 commit 07c0919
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
32 changes: 17 additions & 15 deletions plugins/removeScriptElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}
}
},
Expand Down
19 changes: 19 additions & 0 deletions test/plugins/removeScriptElement.05.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 07c0919

Please sign in to comment.