1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

fix(std/http): properly return port 80 in _parseAddrFromStr (#6635)

This commit is contained in:
Evan Bertrand 2020-07-09 03:37:50 -04:00 committed by GitHub
parent be7e0f2d49
commit e92cf5b9e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View file

@ -262,7 +262,10 @@ export function _parseAddrFromStr(addr: string): HTTPOptions {
throw new TypeError("Invalid address.");
}
return { hostname: url.hostname, port: Number(url.port) };
return {
hostname: url.hostname,
port: url.port === "" ? 80 : Number(url.port),
};
}
/**

View file

@ -629,20 +629,20 @@ Deno.test({
port: 8124,
transport: "tcp",
};
assertEquals(expected, server.listener.addr);
assertEquals(server.listener.addr, expected);
server.close();
},
});
Deno.test({
name: "server.parseAddrFromStr() should be able to parse IPV6 address",
name: "server._parseAddrFromStr() should be able to parse IPV6 address",
fn: (): void => {
const addr = _parseAddrFromStr("[::1]:8124");
const expected = {
hostname: "[::1]",
port: 8124,
};
assertEquals(expected, addr);
assertEquals(addr, expected);
},
});
@ -655,7 +655,15 @@ Deno.test({
port: 8124,
transport: "tcp",
};
assertEquals(expected, server.listener.addr);
assertEquals(server.listener.addr, expected);
server.close();
},
});
Deno.test({
name: "server._parseAddrFromStr() port 80",
fn: (): void => {
const addr = _parseAddrFromStr(":80");
assertEquals(addr.port, 80);
},
});