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:
parent
821a4ae5fd
commit
1500547afa
2 changed files with 11 additions and 3 deletions
|
@ -224,7 +224,7 @@ unitTest(function throwForInvalidPortConstructor(): void {
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const url of urls) {
|
for (const url of urls) {
|
||||||
assertThrows(() => new URL(url));
|
assertThrows(() => new URL(url), TypeError, "Invalid URL.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not throw for 0 & 65535
|
// Do not throw for 0 & 65535
|
||||||
|
@ -232,6 +232,14 @@ unitTest(function throwForInvalidPortConstructor(): void {
|
||||||
new URL("https://baz.qat:0");
|
new URL("https://baz.qat:0");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
unitTest(function throwForInvalidSchemeConstructor(): void {
|
||||||
|
assertThrows(
|
||||||
|
() => new URL("invalid_scheme://baz.qat"),
|
||||||
|
TypeError,
|
||||||
|
"Invalid URL."
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
unitTest(function doNotOverridePortIfInvalid(): void {
|
unitTest(function doNotOverridePortIfInvalid(): void {
|
||||||
const initialPort = "3000";
|
const initialPort = "3000";
|
||||||
const ports = [
|
const ports = [
|
||||||
|
|
|
@ -370,7 +370,7 @@ export class URLImpl implements URL {
|
||||||
throw new TypeError("Invalid 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) {
|
if (this.#validatePort(port) === undefined) {
|
||||||
throw new TypeError("Invalid URL.");
|
throw new TypeError("Invalid URL.");
|
||||||
}
|
}
|
||||||
|
@ -389,7 +389,7 @@ export class URLImpl implements URL {
|
||||||
hash: urlParts.hash,
|
hash: urlParts.hash,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError("URL requires a base URL.");
|
throw new TypeError("Invalid URL.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#updateSearchParams();
|
this.#updateSearchParams();
|
||||||
|
|
Loading…
Reference in a new issue