Skip to content

Commit

Permalink
fix: verify that svgoConfig.plugins is an array (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmeuli committed Feb 16, 2020
1 parent 96966eb commit 88110b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/plugin-svgo/src/index.js
Expand Up @@ -97,7 +97,13 @@ function getFilePath(state) {
}

function getPlugins(config) {
return config && Array.isArray(config.plugins) ? config.plugins : []
if (!config || !config.plugins) {
return []
}
if (!Array.isArray(config.plugins)) {
throw Error("`svgoConfig.plugins` must be an array")
}
return config.plugins
}

function extendPlugins(...configs) {
Expand Down
14 changes: 14 additions & 0 deletions packages/plugin-svgo/src/index.test.js
Expand Up @@ -38,6 +38,20 @@ describe('svgo', () => {
expect(result).toMatchSnapshot()
})

it('should throw error for invalid config.svgoConfig', () => {
const svgoOptions = [
baseSvg,
{
svgo: true,
runtimeConfig: true,
svgoConfig: { plugins: { removeDesc: false } },
},
{},
]

expect(() => svgo(...svgoOptions)).toThrow()
})

it('should support icon with config.svgoConfig plugins', () => {
const result = svgo(
baseSvg,
Expand Down

1 comment on commit 88110b6

@vercel
Copy link

@vercel vercel bot commented on 88110b6 Feb 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.