summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/testdata/run/077_fetch_empty.ts.out2
-rw-r--r--cli/tests/unit/url_test.ts30
-rw-r--r--ext/url/00_url.js9
3 files changed, 25 insertions, 16 deletions
diff --git a/cli/tests/testdata/run/077_fetch_empty.ts.out b/cli/tests/testdata/run/077_fetch_empty.ts.out
index e546cfcec..797574350 100644
--- a/cli/tests/testdata/run/077_fetch_empty.ts.out
+++ b/cli/tests/testdata/run/077_fetch_empty.ts.out
@@ -1,2 +1,2 @@
-[WILDCARD]error: Uncaught TypeError: Invalid URL
+[WILDCARD]error: Uncaught TypeError: Invalid URL: ''
[WILDCARD]
diff --git a/cli/tests/unit/url_test.ts b/cli/tests/unit/url_test.ts
index 0ba848add..1faf33cd0 100644
--- a/cli/tests/unit/url_test.ts
+++ b/cli/tests/unit/url_test.ts
@@ -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() {
diff --git a/ext/url/00_url.js b/ext/url/00_url.js
index 5479cb59c..ebb7b6277 100644
--- a/ext/url/00_url.js
+++ b/ext/url/00_url.js
@@ -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}'` : ""),
+ );
}
}