Skip to content

Commit 8c53102

Browse files
authored
fix: do not allow empty string for port (#3372)
1 parent 4feeb8f commit 8c53102

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

lib/options.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@
523523
"type": "number"
524524
},
525525
{
526-
"type": "string"
526+
"type": "string",
527+
"minLength": 1
527528
},
528529
{
529530
"enum": ["auto"]

test/__snapshots__/validate-options.test.js.snap.webpack4

+9-4
Original file line numberDiff line numberDiff line change
@@ -414,25 +414,30 @@ exports[`options validate should throw an error on the "open" option with '{"tar
414414
* configuration.open.target should be a non-empty string."
415415
`;
416416

417+
exports[`options validate should throw an error on the "port" option with '' value 1`] = `
418+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
419+
- configuration.port should be an non-empty string."
420+
`;
421+
417422
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
418423
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
419424
- configuration.port should be one of these:
420-
number | string | \\"auto\\"
425+
number | non-empty string | \\"auto\\"
421426
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
422427
Details:
423428
* configuration.port should be a number.
424-
* configuration.port should be a string.
429+
* configuration.port should be a non-empty string.
425430
* configuration.port should be \\"auto\\"."
426431
`;
427432

428433
exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
429434
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
430435
- configuration.port should be one of these:
431-
number | string | \\"auto\\"
436+
number | non-empty string | \\"auto\\"
432437
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
433438
Details:
434439
* configuration.port should be a number.
435-
* configuration.port should be a string.
440+
* configuration.port should be a non-empty string.
436441
* configuration.port should be \\"auto\\"."
437442
`;
438443

test/__snapshots__/validate-options.test.js.snap.webpack5

+9-4
Original file line numberDiff line numberDiff line change
@@ -414,25 +414,30 @@ exports[`options validate should throw an error on the "open" option with '{"tar
414414
* configuration.open.target should be a non-empty string."
415415
`;
416416

417+
exports[`options validate should throw an error on the "port" option with '' value 1`] = `
418+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
419+
- configuration.port should be an non-empty string."
420+
`;
421+
417422
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
418423
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
419424
- configuration.port should be one of these:
420-
number | string | \\"auto\\"
425+
number | non-empty string | \\"auto\\"
421426
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
422427
Details:
423428
* configuration.port should be a number.
424-
* configuration.port should be a string.
429+
* configuration.port should be a non-empty string.
425430
* configuration.port should be \\"auto\\"."
426431
`;
427432

428433
exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
429434
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
430435
- configuration.port should be one of these:
431-
number | string | \\"auto\\"
436+
number | non-empty string | \\"auto\\"
432437
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
433438
Details:
434439
* configuration.port should be a number.
435-
* configuration.port should be a string.
440+
* configuration.port should be a non-empty string.
436441
* configuration.port should be \\"auto\\"."
437442
`;
438443

test/validate-options.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ const tests = {
258258
failure: ['', [], { foo: 'bar' }, { target: 90 }, { app: true }],
259259
},
260260
port: {
261-
success: ['', 0, 'auto'],
262-
failure: [false, null],
261+
success: ['8080', 8080, 'auto'],
262+
failure: [false, null, ''],
263263
},
264264
proxy: {
265265
success: [

0 commit comments

Comments
 (0)