2020-01-02 15:13:47 -05:00
|
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-03-04 11:31:14 -05:00
|
|
|
|
import { unitTest, assert, assertEquals, assertThrows } from "./test_util.ts";
|
2018-12-17 20:07:47 -05:00
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function urlParsing(): void {
|
2018-12-17 20:07:47 -05:00
|
|
|
|
const url = new URL(
|
|
|
|
|
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat"
|
|
|
|
|
);
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.hash, "#qat");
|
|
|
|
|
assertEquals(url.host, "baz.qat:8000");
|
|
|
|
|
assertEquals(url.hostname, "baz.qat");
|
|
|
|
|
assertEquals(
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.href,
|
|
|
|
|
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat"
|
|
|
|
|
);
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.origin, "https://baz.qat:8000");
|
|
|
|
|
assertEquals(url.password, "bar");
|
|
|
|
|
assertEquals(url.pathname, "/qux/quux");
|
|
|
|
|
assertEquals(url.port, "8000");
|
|
|
|
|
assertEquals(url.protocol, "https:");
|
|
|
|
|
assertEquals(url.search, "?foo=bar&baz=12");
|
|
|
|
|
assertEquals(url.searchParams.getAll("foo"), ["bar"]);
|
|
|
|
|
assertEquals(url.searchParams.getAll("baz"), ["12"]);
|
|
|
|
|
assertEquals(url.username, "foo");
|
|
|
|
|
assertEquals(
|
2018-12-17 20:07:47 -05:00
|
|
|
|
String(url),
|
|
|
|
|
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat"
|
|
|
|
|
);
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(
|
2018-12-17 20:07:47 -05:00
|
|
|
|
JSON.stringify({ key: url }),
|
|
|
|
|
`{"key":"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat"}`
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function urlModifications(): void {
|
2018-12-17 20:07:47 -05:00
|
|
|
|
const url = new URL(
|
|
|
|
|
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat"
|
|
|
|
|
);
|
|
|
|
|
url.hash = "";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(
|
|
|
|
|
url.href,
|
|
|
|
|
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12"
|
|
|
|
|
);
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.host = "qat.baz:8080";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(
|
|
|
|
|
url.href,
|
|
|
|
|
"https://foo:bar@qat.baz:8080/qux/quux?foo=bar&baz=12"
|
|
|
|
|
);
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.hostname = "foo.bar";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(
|
|
|
|
|
url.href,
|
|
|
|
|
"https://foo:bar@foo.bar:8080/qux/quux?foo=bar&baz=12"
|
|
|
|
|
);
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.password = "qux";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(
|
|
|
|
|
url.href,
|
|
|
|
|
"https://foo:qux@foo.bar:8080/qux/quux?foo=bar&baz=12"
|
|
|
|
|
);
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.pathname = "/foo/bar%qat";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.href,
|
|
|
|
|
"https://foo:qux@foo.bar:8080/foo/bar%qat?foo=bar&baz=12"
|
|
|
|
|
);
|
|
|
|
|
url.port = "";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.href, "https://foo:qux@foo.bar/foo/bar%qat?foo=bar&baz=12");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.protocol = "http:";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.href, "http://foo:qux@foo.bar/foo/bar%qat?foo=bar&baz=12");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.search = "?foo=bar&foo=baz";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.href, "http://foo:qux@foo.bar/foo/bar%qat?foo=bar&foo=baz");
|
|
|
|
|
assertEquals(url.searchParams.getAll("foo"), ["bar", "baz"]);
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.username = "foo@bar";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.href,
|
|
|
|
|
"http://foo%40bar:qux@foo.bar/foo/bar%qat?foo=bar&foo=baz"
|
|
|
|
|
);
|
|
|
|
|
url.searchParams.set("bar", "qat");
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.href,
|
|
|
|
|
"http://foo%40bar:qux@foo.bar/foo/bar%qat?foo=bar&foo=baz&bar=qat"
|
|
|
|
|
);
|
|
|
|
|
url.searchParams.delete("foo");
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.href, "http://foo%40bar:qux@foo.bar/foo/bar%qat?bar=qat");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.searchParams.append("foo", "bar");
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.href,
|
|
|
|
|
"http://foo%40bar:qux@foo.bar/foo/bar%qat?bar=qat&foo=bar"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function urlModifyHref(): void {
|
2018-12-17 20:07:47 -05:00
|
|
|
|
const url = new URL("http://example.com/");
|
|
|
|
|
url.href = "https://foo:bar@example.com:8080/baz/qat#qux";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.protocol, "https:");
|
|
|
|
|
assertEquals(url.username, "foo");
|
|
|
|
|
assertEquals(url.password, "bar");
|
|
|
|
|
assertEquals(url.host, "example.com:8080");
|
|
|
|
|
assertEquals(url.hostname, "example.com");
|
|
|
|
|
assertEquals(url.pathname, "/baz/qat");
|
|
|
|
|
assertEquals(url.hash, "#qux");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-28 13:03:49 -04:00
|
|
|
|
unitTest(function urlNormalize(): void {
|
|
|
|
|
const url = new URL("http://example.com");
|
|
|
|
|
assertEquals(url.pathname, "/");
|
|
|
|
|
assertEquals(url.href, "http://example.com/");
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function urlModifyPathname(): void {
|
2018-12-17 20:07:47 -05:00
|
|
|
|
const url = new URL("http://foo.bar/baz%qat/qux%quux");
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.pathname, "/baz%qat/qux%quux");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.pathname = url.pathname;
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.pathname, "/baz%qat/qux%quux");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.pathname = "baz#qat qux";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.pathname, "/baz%23qat%20qux");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.pathname = url.pathname;
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.pathname, "/baz%23qat%20qux");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function urlModifyHash(): void {
|
2018-12-17 20:07:47 -05:00
|
|
|
|
const url = new URL("http://foo.bar");
|
|
|
|
|
url.hash = "%foo bar/qat%qux#bar";
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.hash, "#%foo%20bar/qat%qux#bar");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
url.hash = url.hash;
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.hash, "#%foo%20bar/qat%qux#bar");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function urlSearchParamsReuse(): void {
|
2018-12-17 20:07:47 -05:00
|
|
|
|
const url = new URL(
|
|
|
|
|
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat"
|
|
|
|
|
);
|
|
|
|
|
const sp = url.searchParams;
|
|
|
|
|
url.host = "baz.qat";
|
|
|
|
|
assert(sp === url.searchParams, "Search params should be reused.");
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-04 14:32:54 -04:00
|
|
|
|
unitTest(function urlBackSlashes(): void {
|
|
|
|
|
const url = new URL(
|
|
|
|
|
"https:\\\\foo:bar@baz.qat:8000\\qux\\quux?foo=bar&baz=12#qat"
|
|
|
|
|
);
|
|
|
|
|
assertEquals(
|
|
|
|
|
url.href,
|
|
|
|
|
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
unitTest(function urlRequireHost(): void {
|
|
|
|
|
assertEquals(new URL("file:///").href, "file:///");
|
|
|
|
|
assertThrows(() => {
|
|
|
|
|
new URL("ftp:///");
|
|
|
|
|
});
|
|
|
|
|
assertThrows(() => {
|
|
|
|
|
new URL("http:///");
|
|
|
|
|
});
|
|
|
|
|
assertThrows(() => {
|
|
|
|
|
new URL("https:///");
|
|
|
|
|
});
|
|
|
|
|
assertThrows(() => {
|
|
|
|
|
new URL("ws:///");
|
|
|
|
|
});
|
|
|
|
|
assertThrows(() => {
|
|
|
|
|
new URL("wss:///");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
unitTest(function urlDriveLetter() {
|
|
|
|
|
assertEquals(
|
|
|
|
|
new URL("file:///C:").href,
|
|
|
|
|
Deno.build.os == "windows" ? "file:///C:/" : "file:///C:"
|
|
|
|
|
);
|
|
|
|
|
assertEquals(new URL("http://example.com/C:").href, "http://example.com/C:");
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-18 09:47:45 -04:00
|
|
|
|
unitTest(function urlHostnameUpperCase() {
|
|
|
|
|
assertEquals(new URL("https://EXAMPLE.COM").href, "https://example.com/");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
unitTest(function urlTrim() {
|
|
|
|
|
assertEquals(new URL(" https://example.com ").href, "https://example.com/");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
unitTest(function urlEncoding() {
|
|
|
|
|
assertEquals(
|
|
|
|
|
new URL("https://a !$&*()=,;+'\"@example.com").username,
|
|
|
|
|
"a%20!$&*()%3D,%3B+%27%22"
|
|
|
|
|
);
|
|
|
|
|
assertEquals(
|
|
|
|
|
new URL("https://:a !$&*()=,;+'\"@example.com").password,
|
|
|
|
|
"a%20!$&*()%3D,%3B+%27%22"
|
|
|
|
|
);
|
|
|
|
|
// FIXME: https://url.spec.whatwg.org/#idna
|
|
|
|
|
// assertEquals(
|
|
|
|
|
// new URL("https://a !$&*()=,+'\"").hostname,
|
|
|
|
|
// "a%20%21%24%26%2A%28%29%3D%2C+%27%22"
|
|
|
|
|
// );
|
|
|
|
|
assertEquals(
|
|
|
|
|
new URL("https://example.com/a ~!@$&*()=:/,;+'\"\\").pathname,
|
|
|
|
|
"/a%20~!@$&*()=:/,;+'%22/"
|
|
|
|
|
);
|
|
|
|
|
assertEquals(
|
|
|
|
|
new URL("https://example.com?a ~!@$&*()=:/,;?+'\"\\").search,
|
|
|
|
|
"?a%20~!@$&*()=:/,;?+%27%22\\"
|
|
|
|
|
);
|
|
|
|
|
assertEquals(
|
|
|
|
|
new URL("https://example.com#a ~!@#$&*()=:/,;?+'\"\\").hash,
|
|
|
|
|
"#a%20~!@#$&*()=:/,;?+'%22\\"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function urlBaseURL(): void {
|
2018-12-17 20:07:47 -05:00
|
|
|
|
const base = new URL(
|
|
|
|
|
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat"
|
|
|
|
|
);
|
|
|
|
|
const url = new URL("/foo/bar?baz=foo#qux", base);
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.href, "https://foo:bar@baz.qat:8000/foo/bar?baz=foo#qux");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function urlBaseString(): void {
|
2018-12-17 20:07:47 -05:00
|
|
|
|
const url = new URL(
|
|
|
|
|
"/foo/bar?baz=foo#qux",
|
|
|
|
|
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat"
|
|
|
|
|
);
|
2019-03-06 20:48:46 -05:00
|
|
|
|
assertEquals(url.href, "https://foo:bar@baz.qat:8000/foo/bar?baz=foo#qux");
|
2018-12-17 20:07:47 -05:00
|
|
|
|
});
|
2019-04-29 19:45:20 -04:00
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function urlRelativeWithBase(): void {
|
2019-09-05 20:01:27 -04:00
|
|
|
|
assertEquals(new URL("", "file:///a/a/a").href, "file:///a/a/a");
|
|
|
|
|
assertEquals(new URL(".", "file:///a/a/a").href, "file:///a/a/");
|
|
|
|
|
assertEquals(new URL("..", "file:///a/a/a").href, "file:///a/");
|
|
|
|
|
assertEquals(new URL("b", "file:///a/a/a").href, "file:///a/a/b");
|
|
|
|
|
assertEquals(new URL("b", "file:///a/a/a/").href, "file:///a/a/a/b");
|
|
|
|
|
assertEquals(new URL("b/", "file:///a/a/a").href, "file:///a/a/b/");
|
|
|
|
|
assertEquals(new URL("../b", "file:///a/a/a").href, "file:///a/b");
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-04 14:32:54 -04:00
|
|
|
|
unitTest(function urlDriveLetterBase() {
|
|
|
|
|
assertEquals(
|
|
|
|
|
new URL("/b", "file:///C:/a/b").href,
|
|
|
|
|
Deno.build.os == "windows" ? "file:///C:/b" : "file:///b"
|
|
|
|
|
);
|
|
|
|
|
assertEquals(
|
|
|
|
|
new URL("D:", "file:///C:/a/b").href,
|
|
|
|
|
Deno.build.os == "windows" ? "file:///D:/" : "file:///C:/a/D:"
|
|
|
|
|
);
|
|
|
|
|
assertEquals(
|
|
|
|
|
new URL("/D:", "file:///C:/a/b").href,
|
|
|
|
|
Deno.build.os == "windows" ? "file:///D:/" : "file:///D:"
|
|
|
|
|
);
|
|
|
|
|
assertEquals(
|
|
|
|
|
new URL("D:/b", "file:///C:/a/b").href,
|
|
|
|
|
Deno.build.os == "windows" ? "file:///D:/b" : "file:///C:/a/D:/b"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function emptyBasePath(): void {
|
2019-09-11 16:20:54 -04:00
|
|
|
|
assertEquals(new URL("", "http://example.com").href, "http://example.com/");
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function deletingAllParamsRemovesQuestionMarkFromURL(): void {
|
2019-04-29 19:45:20 -04:00
|
|
|
|
const url = new URL("http://example.com/?param1¶m2");
|
|
|
|
|
url.searchParams.delete("param1");
|
|
|
|
|
url.searchParams.delete("param2");
|
|
|
|
|
assertEquals(url.href, "http://example.com/");
|
|
|
|
|
assertEquals(url.search, "");
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function removingNonExistentParamRemovesQuestionMarkFromURL(): void {
|
2019-04-29 19:45:20 -04:00
|
|
|
|
const url = new URL("http://example.com/?");
|
|
|
|
|
assertEquals(url.href, "http://example.com/?");
|
|
|
|
|
url.searchParams.delete("param1");
|
|
|
|
|
assertEquals(url.href, "http://example.com/");
|
|
|
|
|
assertEquals(url.search, "");
|
|
|
|
|
});
|
2019-06-10 23:55:38 -04:00
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function sortingNonExistentParamRemovesQuestionMarkFromURL(): void {
|
2019-06-10 23:55:38 -04:00
|
|
|
|
const url = new URL("http://example.com/?");
|
|
|
|
|
assertEquals(url.href, "http://example.com/?");
|
|
|
|
|
url.searchParams.sort();
|
|
|
|
|
assertEquals(url.href, "http://example.com/");
|
|
|
|
|
assertEquals(url.search, "");
|
|
|
|
|
});
|
2019-10-31 14:55:54 -04:00
|
|
|
|
|
2020-03-10 11:38:02 -04:00
|
|
|
|
unitTest(
|
|
|
|
|
{
|
|
|
|
|
// FIXME(bartlomieju)
|
2020-03-28 13:03:49 -04:00
|
|
|
|
ignore: true,
|
2020-03-10 11:38:02 -04:00
|
|
|
|
},
|
|
|
|
|
function customInspectFunction(): void {
|
|
|
|
|
const url = new URL("http://example.com/?");
|
|
|
|
|
assertEquals(
|
|
|
|
|
Deno.inspect(url),
|
|
|
|
|
'URL { href: "http://example.com/?", origin: "http://example.com", protocol: "http:", username: "", password: "", host: "example.com", hostname: "example.com", port: "", pathname: "/", hash: "", search: "?" }'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2019-11-12 13:45:48 -05:00
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function protocolNotHttpOrFile() {
|
2019-11-12 13:45:48 -05:00
|
|
|
|
const url = new URL("about:blank");
|
|
|
|
|
assertEquals(url.href, "about:blank");
|
|
|
|
|
assertEquals(url.protocol, "about:");
|
|
|
|
|
assertEquals(url.origin, "null");
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
|
unitTest(function createBadUrl(): void {
|
2019-11-12 13:45:48 -05:00
|
|
|
|
assertThrows(() => {
|
|
|
|
|
new URL("0.0.0.0:8080");
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-04-28 01:23:06 -04:00
|
|
|
|
|
|
|
|
|
unitTest(function throwForInvalidPortConstructor(): void {
|
|
|
|
|
const urls = [
|
|
|
|
|
// If port is greater than 2^16 − 1, validation error, return failure.
|
|
|
|
|
`https://baz.qat:${2 ** 16}`,
|
|
|
|
|
"https://baz.qat:-32",
|
|
|
|
|
"https://baz.qat:deno",
|
2020-04-28 10:40:17 -04:00
|
|
|
|
"https://baz.qat:9land",
|
|
|
|
|
"https://baz.qat:10.5",
|
2020-04-28 01:23:06 -04:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (const url of urls) {
|
2020-05-04 10:06:47 -04:00
|
|
|
|
assertThrows(() => new URL(url), TypeError, "Invalid URL.");
|
2020-04-28 01:23:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-28 10:40:17 -04:00
|
|
|
|
// Do not throw for 0 & 65535
|
|
|
|
|
new URL("https://baz.qat:65535");
|
|
|
|
|
new URL("https://baz.qat:0");
|
2020-04-28 01:23:06 -04:00
|
|
|
|
});
|
|
|
|
|
|
2020-05-04 10:06:47 -04:00
|
|
|
|
unitTest(function throwForInvalidSchemeConstructor(): void {
|
|
|
|
|
assertThrows(
|
|
|
|
|
() => new URL("invalid_scheme://baz.qat"),
|
|
|
|
|
TypeError,
|
|
|
|
|
"Invalid URL."
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 01:23:06 -04:00
|
|
|
|
unitTest(function doNotOverridePortIfInvalid(): void {
|
|
|
|
|
const initialPort = "3000";
|
|
|
|
|
const ports = [
|
|
|
|
|
// If port is greater than 2^16 − 1, validation error, return failure.
|
|
|
|
|
`${2 ** 16}`,
|
|
|
|
|
"-32",
|
|
|
|
|
"deno",
|
2020-04-28 10:40:17 -04:00
|
|
|
|
"9land",
|
|
|
|
|
"10.5",
|
2020-04-28 01:23:06 -04:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (const port of ports) {
|
|
|
|
|
const url = new URL(`https://deno.land:${initialPort}`);
|
|
|
|
|
url.port = port;
|
|
|
|
|
assertEquals(url.port, initialPort);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
unitTest(function emptyPortForSchemeDefaultPort(): void {
|
|
|
|
|
const nonDefaultPort = "3500";
|
|
|
|
|
const urls = [
|
|
|
|
|
{ url: "ftp://baz.qat:21", port: "21", protocol: "ftp:" },
|
|
|
|
|
{ url: "https://baz.qat:443", port: "443", protocol: "https:" },
|
|
|
|
|
{ url: "wss://baz.qat:443", port: "443", protocol: "wss:" },
|
|
|
|
|
{ url: "http://baz.qat:80", port: "80", protocol: "http:" },
|
|
|
|
|
{ url: "ws://baz.qat:80", port: "80", protocol: "ws:" },
|
|
|
|
|
{ url: "file://home/index.html", port: "", protocol: "file:" },
|
|
|
|
|
{ url: "/foo", baseUrl: "ftp://baz.qat:21", port: "21", protocol: "ftp:" },
|
|
|
|
|
{
|
|
|
|
|
url: "/foo",
|
|
|
|
|
baseUrl: "https://baz.qat:443",
|
|
|
|
|
port: "443",
|
|
|
|
|
protocol: "https:",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
url: "/foo",
|
|
|
|
|
baseUrl: "wss://baz.qat:443",
|
|
|
|
|
port: "443",
|
|
|
|
|
protocol: "wss:",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
url: "/foo",
|
|
|
|
|
baseUrl: "http://baz.qat:80",
|
|
|
|
|
port: "80",
|
|
|
|
|
protocol: "http:",
|
|
|
|
|
},
|
|
|
|
|
{ url: "/foo", baseUrl: "ws://baz.qat:80", port: "80", protocol: "ws:" },
|
|
|
|
|
{
|
|
|
|
|
url: "/foo",
|
|
|
|
|
baseUrl: "file://home/index.html",
|
|
|
|
|
port: "",
|
|
|
|
|
protocol: "file:",
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (const { url: urlString, baseUrl, port, protocol } of urls) {
|
|
|
|
|
const url = new URL(urlString, baseUrl);
|
|
|
|
|
assertEquals(url.port, "");
|
|
|
|
|
|
|
|
|
|
url.port = nonDefaultPort;
|
|
|
|
|
assertEquals(url.port, nonDefaultPort);
|
|
|
|
|
|
|
|
|
|
url.port = port;
|
|
|
|
|
assertEquals(url.port, "");
|
|
|
|
|
|
|
|
|
|
// change scheme
|
|
|
|
|
url.protocol = "sftp:";
|
|
|
|
|
assertEquals(url.port, port);
|
|
|
|
|
|
|
|
|
|
url.protocol = protocol;
|
|
|
|
|
assertEquals(url.port, "");
|
|
|
|
|
}
|
|
|
|
|
});
|