summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/tests/url_test.ts22
-rw-r--r--cli/js/web/url.ts6
2 files changed, 10 insertions, 18 deletions
diff --git a/cli/js/tests/url_test.ts b/cli/js/tests/url_test.ts
index e8348b206..12e7cb26a 100644
--- a/cli/js/tests/url_test.ts
+++ b/cli/js/tests/url_test.ts
@@ -219,27 +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));
}
-});
-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",
- ];
-
- for (const port of ports) {
- const url = new URL(`https://deno.land:${initialPort}`);
- url.port = port;
- assertEquals(url.port, initialPort);
- }
+ // Do not throw for 0 & 65535
+ new URL("https://baz.qat:65535");
+ new URL("https://baz.qat:0");
});
unitTest(function doNotOverridePortIfInvalid(): void {
@@ -249,6 +239,8 @@ unitTest(function doNotOverridePortIfInvalid(): void {
`${2 ** 16}`,
"-32",
"deno",
+ "9land",
+ "10.5",
];
for (const port of ports) {
diff --git a/cli/js/web/url.ts b/cli/js/web/url.ts
index 77285e456..6a8dc6627 100644
--- a/cli/js/web/url.ts
+++ b/cli/js/web/url.ts
@@ -193,10 +193,10 @@ export class URLImpl implements URL {
// https://url.spec.whatwg.org/#port-state
if (value === "") return value;
- const port = parseInt(value, 10);
-
- if (!Number.isNaN(port) && port > 0 && port <= MAX_PORT)
+ const port = Number(value);
+ if (Number.isInteger(port) && port >= 0 && port <= MAX_PORT) {
return port.toString();
+ }
return undefined;
};