Skip to content

Commit

Permalink
fix: do not allow absolute path in chunkFilename (#879)
Browse files Browse the repository at this point in the history
* fix: do not allow absolute path in chunkFilename

* fix: add test for empty path
  • Loading branch information
anshumanv committed Dec 7, 2021
1 parent 76361df commit 36e04ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/plugin-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"chunkFilename": {
"anyOf": [
{
"type": "string"
"type": "string",
"absolutePath": false,
"minLength": 1
},
{
"instanceof": "Function"
Expand Down
19 changes: 17 additions & 2 deletions test/__snapshots__/validate-plugin-options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,32 @@ exports[`validate options should throw an error on the "attributes" option with
-> Read more at https://github.com/webpack-contrib/mini-css-extract-plugin#attributes"
`;

exports[`validate options should throw an error on the "chunkFilename" option with "" value 1`] = `
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
- options.chunkFilename should be a non-empty string."
`;

exports[`validate options should throw an error on the "chunkFilename" option with "/styles/[id].css" value 1`] = `
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
- options.chunkFilename: A relative path is expected. However, the provided value \\"/styles/[id].css\\" is an absolute path!"
`;

exports[`validate options should throw an error on the "chunkFilename" option with "true" value 1`] = `
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
- options.chunkFilename should be one of these:
string | function
non-empty string | function
-> This option determines the name of non-entry chunk files.
-> Read more at https://github.com/webpack-contrib/mini-css-extract-plugin#chunkfilename
Details:
* options.chunkFilename should be a string.
* options.chunkFilename should be a non-empty string.
* options.chunkFilename should be an instance of function."
`;

exports[`validate options should throw an error on the "filename" option with "" value 1`] = `
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
- options.filename should be a non-empty string."
`;

exports[`validate options should throw an error on the "filename" option with "/styles/[name].css" value 1`] = `
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
- options.filename: A relative path is expected. However, the provided value \\"/styles/[name].css\\" is an absolute path!"
Expand Down
4 changes: 2 additions & 2 deletions test/validate-plugin-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ describe("validate options", () => {
"[name].css",
({ name }) => `${name.replace("/js/", "/css/")}.css`,
],
failure: [true, "/styles/[name].css"],
failure: [true, "/styles/[name].css", ""],
},
chunkFilename: {
success: ["[id].css", ({ chunk }) => `${chunk.id}.${chunk.name}.css`],
failure: [true],
failure: [true, "/styles/[id].css", ""],
},
ignoreOrder: {
success: [true, false],
Expand Down

0 comments on commit 36e04ab

Please sign in to comment.