Skip to content

Commit

Permalink
fix: warn and do not crash on null plugin (#1803)
Browse files Browse the repository at this point in the history
If we received null/undefined/empty plugins, instead of crashing, log a
warning and ignore them.
  • Loading branch information
SethFalco committed Oct 22, 2023
1 parent 6eac770 commit c51dcfa
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/svgo.js
Expand Up @@ -65,12 +65,20 @@ const optimize = (input, config) => {
info.multipassCount = i;
const ast = parseSvg(input, config.path);
const plugins = config.plugins || ['preset-default'];
if (Array.isArray(plugins) === false) {
if (!Array.isArray(plugins)) {
throw Error(
"Invalid plugins list. Provided 'plugins' in config should be an array."
'malformed config, `plugins` property must be an array.\nSee more info here: https://github.com/svg/svgo#configuration'
);
}
const resolvedPlugins = plugins
.filter((plugin) => plugin != null)
.map(resolvePluginConfig);

if (resolvedPlugins.length < plugins.length) {
console.warn(
'Warning: plugins list includes null or undefined elements, these will be ignored.'
);
}
const resolvedPlugins = plugins.map(resolvePluginConfig);
const globalOverrides = {};
if (config.floatPrecision != null) {
globalOverrides.floatPrecision = config.floatPrecision;
Expand Down

0 comments on commit c51dcfa

Please sign in to comment.