url: Make zero a valid port (#4963)

This commit is contained in:
Marcos Casagrande 2020-04-28 16:40:17 +02:00 committed by GitHub
parent 5a03e42117
commit 927a771fa4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 19 deletions

View file

@ -219,11 +219,17 @@ unitTest(function throwForInvalidPortConstructor(): void {
`https://baz.qat:${2 ** 16}`,
"https://baz.qat:-32",
"https://baz.qat:deno",
"https://baz.qat:9land",
"https://baz.qat:10.5",
];
for (const url of urls) {
assertThrows(() => new URL(url));
}
// Do not throw for 0 & 65535
new URL("https://baz.qat:65535");
new URL("https://baz.qat:0");
});
unitTest(function doNotOverridePortIfInvalid(): void {
@ -233,22 +239,8 @@ unitTest(function doNotOverridePortIfInvalid(): void {
`${2 ** 16}`,
"-32",
"deno",
];
for (const port of ports) {
const url = new URL(`https://deno.land:${initialPort}`);
url.port = port;
assertEquals(url.port, initialPort);
}
});
unitTest(function doNotOverridePortIfInvalid(): void {
const initialPort = "3000";
const ports = [
// If port is greater than 2^16 1, validation error, return failure.
`${2 ** 16}`,
"-32",
"deno",
"9land",
"10.5",
];
for (const port of ports) {