1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix: URL constructor throws confusing error on invalid scheme (#5057)

This commit is contained in:
Daniel Lenksjö 2020-05-04 16:06:47 +02:00 committed by GitHub
parent 821a4ae5fd
commit 1500547afa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -224,7 +224,7 @@ unitTest(function throwForInvalidPortConstructor(): void {
];
for (const url of urls) {
assertThrows(() => new URL(url));
assertThrows(() => new URL(url), TypeError, "Invalid URL.");
}
// Do not throw for 0 & 65535
@ -232,6 +232,14 @@ unitTest(function throwForInvalidPortConstructor(): void {
new URL("https://baz.qat:0");
});
unitTest(function throwForInvalidSchemeConstructor(): void {
assertThrows(
() => new URL("invalid_scheme://baz.qat"),
TypeError,
"Invalid URL."
);
});
unitTest(function doNotOverridePortIfInvalid(): void {
const initialPort = "3000";
const ports = [

View file

@ -370,7 +370,7 @@ export class URLImpl implements URL {
throw new TypeError("Invalid URL.");
}
const { port } = (urlParts.protocol ? urlParts : baseParts) as URLParts;
const { port } = !urlParts.protocol && baseParts ? baseParts : urlParts;
if (this.#validatePort(port) === undefined) {
throw new TypeError("Invalid URL.");
}
@ -389,7 +389,7 @@ export class URLImpl implements URL {
hash: urlParts.hash,
});
} else {
throw new TypeError("URL requires a base URL.");
throw new TypeError("Invalid URL.");
}
this.#updateSearchParams();