Skip to content

Commit

Permalink
fix: validate absolute paths in filename (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed Dec 7, 2021
1 parent e8c08a1 commit 76361df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/plugin-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"filename": {
"anyOf": [
{
"type": "string"
"type": "string",
"absolutePath": false,
"minLength": 1
},
{
"instanceof": "Function"
Expand Down
9 changes: 7 additions & 2 deletions test/__snapshots__/validate-plugin-options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ exports[`validate options should throw an error on the "chunkFilename" option wi
* options.chunkFilename should be an instance of function."
`;

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!"
`;

exports[`validate options should throw an error on the "filename" 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.filename should be one of these:
string | function
non-empty string | function
-> This option determines the name of each output CSS file.
-> Read more at https://github.com/webpack-contrib/mini-css-extract-plugin#filename
Details:
* options.filename should be a string.
* options.filename should be a non-empty string.
* options.filename should be an instance of function."
`;

Expand Down
2 changes: 1 addition & 1 deletion test/validate-plugin-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("validate options", () => {
"[name].css",
({ name }) => `${name.replace("/js/", "/css/")}.css`,
],
failure: [true],
failure: [true, "/styles/[name].css"],
},
chunkFilename: {
success: ["[id].css", ({ chunk }) => `${chunk.id}.${chunk.name}.css`],
Expand Down

0 comments on commit 76361df

Please sign in to comment.