Skip to content

Commit

Permalink
fix(ext/url): throw TypeError for empty argument (#18896)
Browse files Browse the repository at this point in the history
Fixes #18893
  • Loading branch information
petamoriken authored and levex committed May 4, 2023
1 parent fcb0ae6 commit 084e7c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cli/tests/unit/url_test.ts
Expand Up @@ -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:");
Expand Down
2 changes: 2 additions & 0 deletions ext/url/00_url.js
Expand Up @@ -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, {
Expand All @@ -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, {
Expand Down

0 comments on commit 084e7c9

Please sign in to comment.