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 empty string for port #3372

Merged
merged 2 commits into from
Jun 1, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/options.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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