1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

fix(ext/url): throw TypeError for empty argument (#18896)

Fixes #18893
This commit is contained in:
Kenta Moriuchi 2023-04-30 19:24:34 +09:00 committed by Levente Kurusa
parent fcb0ae62e9
commit 084e7c9560
No known key found for this signature in database
GPG key ID: 9F72F3C05BA137C4
2 changed files with 17 additions and 0 deletions

View file

@ -32,6 +32,21 @@ Deno.test(function urlParsing() {
);
});
Deno.test(function emptyUrl() {
assertThrows(
// @ts-ignore for test
() => new URL(),
TypeError,
"1 argument required, but only 0 present",
);
assertThrows(
// @ts-ignore for test
() => URL.canParse(),
TypeError,
"1 argument required, but only 0 present",
);
});
Deno.test(function urlProtocolParsing() {
assertEquals(new URL("Aa+-.1://foo").protocol, "aa+-.1:");
assertEquals(new URL("aA+-.1://foo").protocol, "aa+-.1:");

View file

@ -371,6 +371,7 @@ class URL {
*/
constructor(url, base = undefined) {
const prefix = "Failed to construct 'URL'";
webidl.requiredArguments(arguments.length, 1, prefix);
url = webidl.converters.DOMString(url, { prefix, context: "Argument 1" });
if (base !== undefined) {
base = webidl.converters.DOMString(base, {
@ -390,6 +391,7 @@ class URL {
*/
static canParse(url, base = undefined) {
const prefix = "Failed to call 'URL.canParse'";
webidl.requiredArguments(arguments.length, 1, prefix);
url = webidl.converters.DOMString(url, { prefix, context: "Argument 1" });
if (base !== undefined) {
base = webidl.converters.DOMString(base, {