Skip to content

Commit 17aa345

Browse files
authored
fix: don't allow empty array for allowedHosts option (#3451)
1 parent 5c8fa5b commit 17aa345

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

lib/options.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"anyOf": [
77
{
88
"type": "array",
9+
"minItems": 1,
910
"items": {
1011
"$ref": "#/definitions/AllowedHostsItem"
1112
}

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

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`options validate should throw an error on the "allowedHosts" option with '[""]' value 1`] = `
4+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
5+
- options.allowedHosts[0] should be an non-empty string."
6+
`;
7+
8+
exports[`options validate should throw an error on the "allowedHosts" option with '[]' value 1`] = `
9+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
10+
- options.allowedHosts should be an non-empty array."
11+
`;
12+
313
exports[`options validate should throw an error on the "allowedHosts" option with '123' value 1`] = `
414
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
515
- options.allowedHosts should be one of these:
6-
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
16+
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
717
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
818
Details:
919
* options.allowedHosts should be an array:
10-
[non-empty string, ...]
20+
[non-empty string, ...] (should not have fewer than 1 item)
1121
* options.allowedHosts should be one of these:
1222
\\"auto\\" | \\"all\\"
1323
* options.allowedHosts should be a non-empty string."
@@ -16,11 +26,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit
1626
exports[`options validate should throw an error on the "allowedHosts" option with 'false' value 1`] = `
1727
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
1828
- options.allowedHosts should be one of these:
19-
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
29+
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
2030
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
2131
Details:
2232
* options.allowedHosts should be an array:
23-
[non-empty string, ...]
33+
[non-empty string, ...] (should not have fewer than 1 item)
2434
* options.allowedHosts should be one of these:
2535
\\"auto\\" | \\"all\\"
2636
* options.allowedHosts should be a non-empty string."
@@ -29,11 +39,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit
2939
exports[`options validate should throw an error on the "allowedHosts" option with 'true' value 1`] = `
3040
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
3141
- options.allowedHosts should be one of these:
32-
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
42+
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
3343
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
3444
Details:
3545
* options.allowedHosts should be an array:
36-
[non-empty string, ...]
46+
[non-empty string, ...] (should not have fewer than 1 item)
3747
* options.allowedHosts should be one of these:
3848
\\"auto\\" | \\"all\\"
3949
* options.allowedHosts should be a non-empty string."

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

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`options validate should throw an error on the "allowedHosts" option with '[""]' value 1`] = `
4+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
5+
- options.allowedHosts[0] should be an non-empty string."
6+
`;
7+
8+
exports[`options validate should throw an error on the "allowedHosts" option with '[]' value 1`] = `
9+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
10+
- options.allowedHosts should be an non-empty array."
11+
`;
12+
313
exports[`options validate should throw an error on the "allowedHosts" option with '123' value 1`] = `
414
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
515
- options.allowedHosts should be one of these:
6-
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
16+
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
717
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
818
Details:
919
* options.allowedHosts should be an array:
10-
[non-empty string, ...]
20+
[non-empty string, ...] (should not have fewer than 1 item)
1121
* options.allowedHosts should be one of these:
1222
\\"auto\\" | \\"all\\"
1323
* options.allowedHosts should be a non-empty string."
@@ -16,11 +26,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit
1626
exports[`options validate should throw an error on the "allowedHosts" option with 'false' value 1`] = `
1727
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
1828
- options.allowedHosts should be one of these:
19-
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
29+
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
2030
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
2131
Details:
2232
* options.allowedHosts should be an array:
23-
[non-empty string, ...]
33+
[non-empty string, ...] (should not have fewer than 1 item)
2434
* options.allowedHosts should be one of these:
2535
\\"auto\\" | \\"all\\"
2636
* options.allowedHosts should be a non-empty string."
@@ -29,11 +39,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit
2939
exports[`options validate should throw an error on the "allowedHosts" option with 'true' value 1`] = `
3040
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
3141
- options.allowedHosts should be one of these:
32-
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
42+
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
3343
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
3444
Details:
3545
* options.allowedHosts should be an array:
36-
[non-empty string, ...]
46+
[non-empty string, ...] (should not have fewer than 1 item)
3747
* options.allowedHosts should be one of these:
3848
\\"auto\\" | \\"all\\"
3949
* options.allowedHosts should be a non-empty string."

test/validate-options.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const tests = {
167167
},
168168
allowedHosts: {
169169
success: ['auto', 'all', ['foo'], 'bar'],
170-
failure: [true, false, 123],
170+
failure: [true, false, 123, [], ['']],
171171
},
172172
headers: {
173173
success: [{}, { foo: 'bar' }, () => {}],

0 commit comments

Comments
 (0)