Skip to content

Commit ed67f66

Browse files
fix: handle 0 value of the port option property
1 parent 772f6aa commit ed67f66

16 files changed

+994
-1062
lines changed

lib/Server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Server {
7474
}
7575

7676
static async getFreePort(port) {
77-
if (port && port !== "auto") {
77+
if (typeof port !== "undefined" && port !== null && port !== "auto") {
7878
return port;
7979
}
8080

lib/options.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,9 @@
554554
"Port": {
555555
"anyOf": [
556556
{
557-
"type": "number"
557+
"type": "number",
558+
"minimum": 0,
559+
"maximum": 65535
558560
},
559561
{
560562
"type": "string",

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -517,26 +517,36 @@ exports[`options validate should throw an error on the "port" option with '' val
517517
- options.port should be a non-empty string."
518518
`;
519519

520+
exports[`options validate should throw an error on the "port" option with '-1' value 1`] = `
521+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
522+
- options.port should be >= 0 and <= 65535."
523+
`;
524+
525+
exports[`options validate should throw an error on the "port" option with '65536' value 1`] = `
526+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
527+
- options.port should be >= 0 and <= 65535."
528+
`;
529+
520530
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
521531
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
522532
- options.port should be one of these:
523-
number | non-empty string | \\"auto\\"
533+
number (should be >= 0 and <= 65535) | non-empty string | \\"auto\\"
524534
-> Allows to specify a port to use.
525535
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverport
526536
Details:
527-
* options.port should be a number.
537+
* options.port should be a number (should be >= 0 and <= 65535).
528538
* options.port should be a non-empty string.
529539
* options.port should be \\"auto\\"."
530540
`;
531541

532542
exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
533543
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
534544
- options.port should be one of these:
535-
number | non-empty string | \\"auto\\"
545+
number (should be >= 0 and <= 65535) | non-empty string | \\"auto\\"
536546
-> Allows to specify a port to use.
537547
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverport
538548
Details:
539-
* options.port should be a number.
549+
* options.port should be a number (should be >= 0 and <= 65535).
540550
* options.port should be a non-empty string.
541551
* options.port should be \\"auto\\"."
542552
`;

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -517,26 +517,36 @@ exports[`options validate should throw an error on the "port" option with '' val
517517
- options.port should be a non-empty string."
518518
`;
519519

520+
exports[`options validate should throw an error on the "port" option with '-1' value 1`] = `
521+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
522+
- options.port should be >= 0 and <= 65535."
523+
`;
524+
525+
exports[`options validate should throw an error on the "port" option with '65536' value 1`] = `
526+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
527+
- options.port should be >= 0 and <= 65535."
528+
`;
529+
520530
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
521531
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
522532
- options.port should be one of these:
523-
number | non-empty string | \\"auto\\"
533+
number (should be >= 0 and <= 65535) | non-empty string | \\"auto\\"
524534
-> Allows to specify a port to use.
525535
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverport
526536
Details:
527-
* options.port should be a number.
537+
* options.port should be a number (should be >= 0 and <= 65535).
528538
* options.port should be a non-empty string.
529539
* options.port should be \\"auto\\"."
530540
`;
531541

532542
exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
533543
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
534544
- options.port should be one of these:
535-
number | non-empty string | \\"auto\\"
545+
number (should be >= 0 and <= 65535) | non-empty string | \\"auto\\"
536546
-> Allows to specify a port to use.
537547
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverport
538548
Details:
539-
* options.port should be a number.
549+
* options.port should be a number (should be >= 0 and <= 65535).
540550
* options.port should be a non-empty string.
541551
* options.port should be \\"auto\\"."
542552
`;

test/e2e/__snapshots__/host-and-port.test.js.snap.webpack4

-265
This file was deleted.

0 commit comments

Comments
 (0)