mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
fix: display URL in invalid URL error (#17128)
This commit is contained in:
parent
2ff27a1f93
commit
80955dfa61
3 changed files with 25 additions and 16 deletions
|
@ -1,2 +1,2 @@
|
|||
[WILDCARD]error: Uncaught TypeError: Invalid URL
|
||||
[WILDCARD]error: Uncaught TypeError: Invalid URL: ''
|
||||
[WILDCARD]
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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}'` : ""),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue