Skip to content

Commit

Permalink
fix: do not allow empty string for port (#3372)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jun 1, 2021
1 parent 4feeb8f commit 8c53102
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/options.json
Expand Up @@ -523,7 +523,8 @@
"type": "number"
},
{
"type": "string"
"type": "string",
"minLength": 1
},
{
"enum": ["auto"]
Expand Down
13 changes: 9 additions & 4 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Expand Up @@ -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\\"."
`;

Expand Down
13 changes: 9 additions & 4 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Expand Up @@ -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\\"."
`;

Expand Down
4 changes: 2 additions & 2 deletions test/validate-options.test.js
Expand Up @@ -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: [
Expand Down

0 comments on commit 8c53102

Please sign in to comment.