From 76361df4220f62c18b3660af76ab8b28c56d0471 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Tue, 7 Dec 2021 21:16:34 +0530 Subject: [PATCH] fix: validate absolute paths in filename (#878) --- 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 8da511d4..7cacd20b 100644 --- a/src/plugin-options.json +++ b/src/plugin-options.json @@ -6,7 +6,9 @@ "filename": { "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 c849007f..d49a9884 100644 --- a/test/__snapshots__/validate-plugin-options.test.js.snap +++ b/test/__snapshots__/validate-plugin-options.test.js.snap @@ -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." `; diff --git a/test/validate-plugin-options.test.js b/test/validate-plugin-options.test.js index 83a8b7bd..aedefa96 100644 --- a/test/validate-plugin-options.test.js +++ b/test/validate-plugin-options.test.js @@ -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`],