1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix: display URL in invalid URL error (#17128)

This commit is contained in:
Leo Kettmeir 2022-12-19 20:58:02 +01:00 committed by GitHub
parent 2ff27a1f93
commit 80955dfa61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 16 deletions

View file

@ -1,2 +1,2 @@
[WILDCARD]error: Uncaught TypeError: Invalid URL
[WILDCARD]error: Uncaught TypeError: Invalid URL: ''
[WILDCARD]

View file

@ -35,18 +35,24 @@ Deno.test(function urlParsing() {
Deno.test(function urlProtocolParsing() {
assertEquals(new URL("Aa+-.1://foo").protocol, "aa+-.1:");
assertEquals(new URL("aA+-.1://foo").protocol, "aa+-.1:");
assertThrows(() => new URL("1://foo"), TypeError, "Invalid URL");
assertThrows(() => new URL("+://foo"), TypeError, "Invalid URL");
assertThrows(() => new URL("-://foo"), TypeError, "Invalid URL");
assertThrows(() => new URL(".://foo"), TypeError, "Invalid URL");
assertThrows(() => new URL("_://foo"), TypeError, "Invalid URL");
assertThrows(() => new URL("=://foo"), TypeError, "Invalid URL");
assertThrows(() => new URL("!://foo"), TypeError, "Invalid URL");
assertThrows(() => new URL(`"://foo`), TypeError, "Invalid URL");
assertThrows(() => new URL("$://foo"), TypeError, "Invalid URL");
assertThrows(() => new URL("%://foo"), TypeError, "Invalid URL");
assertThrows(() => new URL("^://foo"), TypeError, "Invalid URL");
assertThrows(() => new URL("*://foo"), TypeError, "Invalid URL");
assertThrows(() => new URL("1://foo"), TypeError, "Invalid URL: '1://foo'");
assertThrows(() => new URL("+://foo"), TypeError, "Invalid URL: '+://foo'");
assertThrows(() => new URL("-://foo"), TypeError, "Invalid URL: '-://foo'");
assertThrows(() => new URL(".://foo"), TypeError, "Invalid URL: '.://foo'");
assertThrows(() => new URL("_://foo"), TypeError, "Invalid URL: '_://foo'");
assertThrows(() => new URL("=://foo"), TypeError, "Invalid URL: '=://foo'");
assertThrows(() => new URL("!://foo"), TypeError, "Invalid URL: '!://foo'");
assertThrows(() => new URL(`"://foo`), TypeError, `Invalid URL: '"://foo'`);
assertThrows(() => new URL("$://foo"), TypeError, "Invalid URL: '$://foo'");
assertThrows(() => new URL("%://foo"), TypeError, "Invalid URL: '%://foo'");
assertThrows(() => new URL("^://foo"), TypeError, "Invalid URL: '^://foo'");
assertThrows(() => new URL("*://foo"), TypeError, "Invalid URL: '*://foo'");
assertThrows(() => new URL("*://foo"), TypeError, "Invalid URL: '*://foo'");
assertThrows(
() => new URL("!:", "*://foo"),
TypeError,
"Invalid URL: '!:' with base '*://foo'",
);
});
Deno.test(function urlAuthenticationParsing() {

View file

@ -64,16 +64,19 @@
componentsBuf.buffer,
);
}
return getSerialization(status, href);
return getSerialization(status, href, maybeBase);
}
function getSerialization(status, href) {
function getSerialization(status, href, maybeBase) {
if (status === 0) {
return href;
} else if (status === 1) {
return core.ops.op_url_get_serialization();
} else {
throw new TypeError("Invalid URL");
throw new TypeError(
`Invalid URL: '${href}'` +
(maybeBase ? ` with base '${maybeBase}'` : ""),
);
}
}