Skip to content

Commit 88110b6

Browse files
authored
fix: verify that svgoConfig.plugins is an array (#397)
1 parent 96966eb commit 88110b6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/plugin-svgo/src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,13 @@ function getFilePath(state) {
9797
}
9898

9999
function getPlugins(config) {
100-
return config && Array.isArray(config.plugins) ? config.plugins : []
100+
if (!config || !config.plugins) {
101+
return []
102+
}
103+
if (!Array.isArray(config.plugins)) {
104+
throw Error("`svgoConfig.plugins` must be an array")
105+
}
106+
return config.plugins
101107
}
102108

103109
function extendPlugins(...configs) {

packages/plugin-svgo/src/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ describe('svgo', () => {
3838
expect(result).toMatchSnapshot()
3939
})
4040

41+
it('should throw error for invalid config.svgoConfig', () => {
42+
const svgoOptions = [
43+
baseSvg,
44+
{
45+
svgo: true,
46+
runtimeConfig: true,
47+
svgoConfig: { plugins: { removeDesc: false } },
48+
},
49+
{},
50+
]
51+
52+
expect(() => svgo(...svgoOptions)).toThrow()
53+
})
54+
4155
it('should support icon with config.svgoConfig plugins', () => {
4256
const result = svgo(
4357
baseSvg,

0 commit comments

Comments
 (0)