Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not allow absolute path in chunkFilename #879

Merged
merged 2 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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