Skip to content

Commit 36e04ab

Browse files
authored
fix: do not allow absolute path in chunkFilename (#879)
* fix: do not allow absolute path in chunkFilename * fix: add test for empty path
1 parent 76361df commit 36e04ab

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/plugin-options.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"chunkFilename": {
2121
"anyOf": [
2222
{
23-
"type": "string"
23+
"type": "string",
24+
"absolutePath": false,
25+
"minLength": 1
2426
},
2527
{
2628
"instanceof": "Function"

test/__snapshots__/validate-plugin-options.test.js.snap

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,32 @@ exports[`validate options should throw an error on the "attributes" option with
88
-> Read more at https://github.com/webpack-contrib/mini-css-extract-plugin#attributes"
99
`;
1010

11+
exports[`validate options should throw an error on the "chunkFilename" option with "" value 1`] = `
12+
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
13+
- options.chunkFilename should be a non-empty string."
14+
`;
15+
16+
exports[`validate options should throw an error on the "chunkFilename" option with "/styles/[id].css" value 1`] = `
17+
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
18+
- options.chunkFilename: A relative path is expected. However, the provided value \\"/styles/[id].css\\" is an absolute path!"
19+
`;
20+
1121
exports[`validate options should throw an error on the "chunkFilename" option with "true" value 1`] = `
1222
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
1323
- options.chunkFilename should be one of these:
14-
string | function
24+
non-empty string | function
1525
-> This option determines the name of non-entry chunk files.
1626
-> Read more at https://github.com/webpack-contrib/mini-css-extract-plugin#chunkfilename
1727
Details:
18-
* options.chunkFilename should be a string.
28+
* options.chunkFilename should be a non-empty string.
1929
* options.chunkFilename should be an instance of function."
2030
`;
2131

32+
exports[`validate options should throw an error on the "filename" option with "" value 1`] = `
33+
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
34+
- options.filename should be a non-empty string."
35+
`;
36+
2237
exports[`validate options should throw an error on the "filename" option with "/styles/[name].css" value 1`] = `
2338
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
2439
- options.filename: A relative path is expected. However, the provided value \\"/styles/[name].css\\" is an absolute path!"

test/validate-plugin-options.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ describe("validate options", () => {
77
"[name].css",
88
({ name }) => `${name.replace("/js/", "/css/")}.css`,
99
],
10-
failure: [true, "/styles/[name].css"],
10+
failure: [true, "/styles/[name].css", ""],
1111
},
1212
chunkFilename: {
1313
success: ["[id].css", ({ chunk }) => `${chunk.id}.${chunk.name}.css`],
14-
failure: [true],
14+
failure: [true, "/styles/[id].css", ""],
1515
},
1616
ignoreOrder: {
1717
success: [true, false],

0 commit comments

Comments
 (0)