From e21e56060b6290b8a579f55ed46ce644f5a6cfc4 Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Sat, 4 Nov 2023 14:07:29 +0000 Subject: [PATCH] feat(removeScriptElement): add all known event types (#1819) Update the list of event attributes to include everything listed on MDN. --- lib/svgo/tools.js | 4 ++- plugins/_collections.js | 61 +++++++++++++++++++++++++++++++++- plugins/removeScriptElement.js | 4 ++- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/lib/svgo/tools.js b/lib/svgo/tools.js index 0614d6e1d..355c4b39e 100644 --- a/lib/svgo/tools.js +++ b/lib/svgo/tools.js @@ -167,8 +167,10 @@ const hasScripts = (node) => { const eventAttrs = [ ...attrsGroups.animationEvent, - ...attrsGroups.graphicalEvent, ...attrsGroups.documentEvent, + ...attrsGroups.documentElementEvent, + ...attrsGroups.globalEvent, + ...attrsGroups.graphicalEvent, ]; return eventAttrs.some((attr) => node.attributes[attr] != null); diff --git a/plugins/_collections.js b/plugins/_collections.js index dfa8bff60..5ef493e48 100644 --- a/plugins/_collections.js +++ b/plugins/_collections.js @@ -218,13 +218,72 @@ exports.attrsGroups = { 'xlink:title', ], documentEvent: [ - 'onunload', 'onabort', 'onerror', 'onresize', 'onscroll', + 'onunload', 'onzoom', ], + documentElementEvent: ['oncopy', 'oncut', 'onpaste'], + globalEvent: [ + 'oncancel', + 'oncanplay', + 'oncanplaythrough', + 'onchange', + 'onclick', + 'onclose', + 'oncuechange', + 'ondblclick', + 'ondrag', + 'ondragend', + 'ondragenter', + 'ondragleave', + 'ondragover', + 'ondragstart', + 'ondrop', + 'ondurationchange', + 'onemptied', + 'onended', + 'onerror', + 'onfocus', + 'oninput', + 'oninvalid', + 'onkeydown', + 'onkeypress', + 'onkeyup', + 'onload', + 'onloadeddata', + 'onloadedmetadata', + 'onloadstart', + 'onmousedown', + 'onmouseenter', + 'onmouseleave', + 'onmousemove', + 'onmouseout', + 'onmouseover', + 'onmouseup', + 'onmousewheel', + 'onpause', + 'onplay', + 'onplaying', + 'onprogress', + 'onratechange', + 'onreset', + 'onresize', + 'onscroll', + 'onseeked', + 'onseeking', + 'onselect', + 'onshow', + 'onstalled', + 'onsubmit', + 'onsuspend', + 'ontimeupdate', + 'ontoggle', + 'onvolumechange', + 'onwaiting', + ], filterPrimitive: ['x', 'y', 'width', 'height', 'result'], transferFunction: [ 'type', diff --git a/plugins/removeScriptElement.js b/plugins/removeScriptElement.js index 88977729b..eb1a6ba54 100644 --- a/plugins/removeScriptElement.js +++ b/plugins/removeScriptElement.js @@ -9,8 +9,10 @@ exports.description = 'removes scripts (disabled by default)'; /** Union of all event attributes. */ const eventAttrs = [ ...attrsGroups.animationEvent, - ...attrsGroups.graphicalEvent, ...attrsGroups.documentEvent, + ...attrsGroups.documentElementEvent, + ...attrsGroups.globalEvent, + ...attrsGroups.graphicalEvent, ]; /**