1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 08:09:08 -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 GitHub
parent 59825a95b4
commit 74bb09aa38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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, {