From fd8e0aa656814f72db857a43e0c8d3b1d01d1798 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Tue, 7 Dec 2021 21:31:18 +0530 Subject: [PATCH 1/2] fix: do not allow absolute path in chunkFilename --- src/plugin-options.json | 4 +++- test/__snapshots__/validate-plugin-options.test.js.snap | 9 +++++++-- test/validate-plugin-options.test.js | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/plugin-options.json b/src/plugin-options.json index 7cacd20b..eea6cfd1 100644 --- a/src/plugin-options.json +++ b/src/plugin-options.json @@ -20,7 +20,9 @@ "chunkFilename": { "anyOf": [ { - "type": "string" + "type": "string", + "absolutePath": false, + "minLength": 1 }, { "instanceof": "Function" diff --git a/test/__snapshots__/validate-plugin-options.test.js.snap b/test/__snapshots__/validate-plugin-options.test.js.snap index d49a9884..1973e41e 100644 --- a/test/__snapshots__/validate-plugin-options.test.js.snap +++ b/test/__snapshots__/validate-plugin-options.test.js.snap @@ -8,14 +8,19 @@ 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 "/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." `; diff --git a/test/validate-plugin-options.test.js b/test/validate-plugin-options.test.js index aedefa96..7ace0d98 100644 --- a/test/validate-plugin-options.test.js +++ b/test/validate-plugin-options.test.js @@ -11,7 +11,7 @@ describe("validate options", () => { }, chunkFilename: { success: ["[id].css", ({ chunk }) => `${chunk.id}.${chunk.name}.css`], - failure: [true], + failure: [true, "/styles/[id].css"], }, ignoreOrder: { success: [true, false], From dbb3e295cda7c8cd01421367a46350ae8bb04900 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Tue, 7 Dec 2021 21:32:37 +0530 Subject: [PATCH 2/2] fix: add test for empty path --- .../__snapshots__/validate-plugin-options.test.js.snap | 10 ++++++++++ test/validate-plugin-options.test.js | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/__snapshots__/validate-plugin-options.test.js.snap b/test/__snapshots__/validate-plugin-options.test.js.snap index 1973e41e..ff8fb308 100644 --- a/test/__snapshots__/validate-plugin-options.test.js.snap +++ b/test/__snapshots__/validate-plugin-options.test.js.snap @@ -8,6 +8,11 @@ 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!" @@ -24,6 +29,11 @@ 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 "" 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!" diff --git a/test/validate-plugin-options.test.js b/test/validate-plugin-options.test.js index 7ace0d98..ff95fbfc 100644 --- a/test/validate-plugin-options.test.js +++ b/test/validate-plugin-options.test.js @@ -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, "/styles/[id].css"], + failure: [true, "/styles/[id].css", ""], }, ignoreOrder: { success: [true, false],