From 97ce0f058ed6e92a76fb8d69ea58884a7dbc0d8b Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Tue, 1 Jun 2021 19:01:07 +0530 Subject: [PATCH 1/2] fix: do not allow empty string for `port` --- lib/options.json | 3 ++- test/validate-options.test.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/options.json b/lib/options.json index 554f8fe48d..d546d03f37 100644 --- a/lib/options.json +++ b/lib/options.json @@ -523,7 +523,8 @@ "type": "number" }, { - "type": "string" + "type": "string", + "minLength": 1 }, { "enum": ["auto"] diff --git a/test/validate-options.test.js b/test/validate-options.test.js index c5db1a006e..c6e37b72c2 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -258,8 +258,8 @@ const tests = { failure: ['', [], { foo: 'bar' }, { target: 90 }, { app: true }], }, port: { - success: ['', 0, 'auto'], - failure: [false, null], + success: ['8080', 8080, 'auto'], + failure: [false, null, ''], }, proxy: { success: [ From 9ef0fa8a12ce124f95345bd453c46cd2d4725322 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Tue, 1 Jun 2021 19:03:35 +0530 Subject: [PATCH 2/2] test: updates --- .../validate-options.test.js.snap.webpack4 | 13 +++++++++---- .../validate-options.test.js.snap.webpack5 | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack4 b/test/__snapshots__/validate-options.test.js.snap.webpack4 index a69d352d81..a4f107f387 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack4 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack4 @@ -414,25 +414,30 @@ exports[`options validate should throw an error on the "open" option with '{"tar * configuration.open.target should be a non-empty string." `; +exports[`options validate should throw an error on the "port" option with '' value 1`] = ` +"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema. + - configuration.port should be an non-empty string." +`; + exports[`options validate should throw an error on the "port" option with 'false' value 1`] = ` "ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema. - configuration.port should be one of these: - number | string | \\"auto\\" + number | non-empty string | \\"auto\\" -> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport Details: * configuration.port should be a number. - * configuration.port should be a string. + * configuration.port should be a non-empty string. * configuration.port should be \\"auto\\"." `; exports[`options validate should throw an error on the "port" option with 'null' value 1`] = ` "ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema. - configuration.port should be one of these: - number | string | \\"auto\\" + number | non-empty string | \\"auto\\" -> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport Details: * configuration.port should be a number. - * configuration.port should be a string. + * configuration.port should be a non-empty string. * configuration.port should be \\"auto\\"." `; diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack5 b/test/__snapshots__/validate-options.test.js.snap.webpack5 index a69d352d81..a4f107f387 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack5 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack5 @@ -414,25 +414,30 @@ exports[`options validate should throw an error on the "open" option with '{"tar * configuration.open.target should be a non-empty string." `; +exports[`options validate should throw an error on the "port" option with '' value 1`] = ` +"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema. + - configuration.port should be an non-empty string." +`; + exports[`options validate should throw an error on the "port" option with 'false' value 1`] = ` "ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema. - configuration.port should be one of these: - number | string | \\"auto\\" + number | non-empty string | \\"auto\\" -> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport Details: * configuration.port should be a number. - * configuration.port should be a string. + * configuration.port should be a non-empty string. * configuration.port should be \\"auto\\"." `; exports[`options validate should throw an error on the "port" option with 'null' value 1`] = ` "ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema. - configuration.port should be one of these: - number | string | \\"auto\\" + number | non-empty string | \\"auto\\" -> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport Details: * configuration.port should be a number. - * configuration.port should be a string. + * configuration.port should be a non-empty string. * configuration.port should be \\"auto\\"." `;