Skip to content

Commit

Permalink
feat(removeScriptElement): add all known event types (#1819)
Browse files Browse the repository at this point in the history
Update the list of event attributes to include everything listed on MDN.
  • Loading branch information
SethFalco authored Nov 4, 2023
1 parent e73ee2d commit e21e560
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/svgo/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
61 changes: 60 additions & 1 deletion plugins/_collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion plugins/removeScriptElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

/**
Expand Down

0 comments on commit e21e560

Please sign in to comment.