1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
import { describe, it, expect } from "bun:test";
describe("url", () => {
it("prints", () => {
expect(Bun.inspect(new URL("https://example.com"))).toBe(
"https://example.com/"
);
expect(
Bun.inspect(
new URL(
"https://github.com/Jarred-Sumner/bun/issues/135?hello%20i%20have%20spaces%20thank%20you%20good%20night"
)
)
).toBe(
"https://github.com/Jarred-Sumner/bun/issues/135?hello%20i%20have%20spaces%20thank%20you%20good%20night"
);
});
it("works", () => {
const inputs: [
[
string,
{
hash: string;
host: string;
hostname: string;
href: string;
origin: string;
password: string;
pathname: string;
port: string;
protocol: string;
search: string;
username: string;
}
]
] = [
[
"https://username:password@api.foo.bar.com:9999/baz/okay/i/123?ran=out&of=things#to-use-as-a-placeholder",
{
hash: "#to-use-as-a-placeholder",
host: "api.foo.bar.com:9999",
hostname: "api.foo.bar.com",
href: "https://username:password@api.foo.bar.com:9999/baz/okay/i/123?ran=out&of=things#to-use-as-a-placeholder",
origin: "https://api.foo.bar.com:9999",
password: "password",
pathname: "/baz/okay/i/123",
port: "9999",
protocol: "https:",
search: "?ran=out&of=things",
username: "username",
},
],
[
"https://url.spec.whatwg.org/#url-serializing",
{
hash: "#url-serializing",
host: "url.spec.whatwg.org",
hostname: "url.spec.whatwg.org",
href: "https://url.spec.whatwg.org/#url-serializing",
origin: "https://url.spec.whatwg.org",
password: "",
pathname: "/",
port: "",
protocol: "https:",
search: "",
username: "",
},
],
[
"https://url.spec.whatwg.org#url-serializing",
{
hash: "#url-serializing",
host: "url.spec.whatwg.org",
hostname: "url.spec.whatwg.org",
href: "https://url.spec.whatwg.org/#url-serializing",
origin: "https://url.spec.whatwg.org",
password: "",
pathname: "/",
port: "",
protocol: "https:",
search: "",
username: "",
},
],
];
for (let [url, values] of inputs) {
const result = new URL(url);
expect(result.hash).toBe(values.hash);
expect(result.host).toBe(values.host);
expect(result.hostname).toBe(values.hostname);
expect(result.href).toBe(values.href);
expect(result.password).toBe(values.password);
expect(result.pathname).toBe(values.pathname);
expect(result.port).toBe(values.port);
expect(result.protocol).toBe(values.protocol);
expect(result.search).toBe(values.search);
expect(result.username).toBe(values.username);
}
});
});
|