Skip to content

Commit 22fa71d

Browse files
authored
fix: open link with search params (#16617)
Fixes: #16501
1 parent 4edd77b commit 22fa71d

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

site/src/utils/portForward.test.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { portForwardURL } from "./portForward";
2+
3+
describe("port forward URL", () => {
4+
const proxyHostWildcard = "*.proxy-host.tld";
5+
const samplePort = 12345;
6+
const sampleAgent = "my-agent";
7+
const sampleWorkspace = "my-workspace";
8+
const sampleUsername = "my-username";
9+
10+
it("https, host and port", () => {
11+
const forwarded = portForwardURL(
12+
proxyHostWildcard,
13+
samplePort,
14+
sampleAgent,
15+
sampleWorkspace,
16+
sampleUsername,
17+
"https",
18+
);
19+
expect(forwarded).toEqual(
20+
"http://12345s--my-agent--my-workspace--my-username.proxy-host.tld/",
21+
);
22+
});
23+
it("http, host, port and path", () => {
24+
const forwarded = portForwardURL(
25+
proxyHostWildcard,
26+
samplePort,
27+
sampleAgent,
28+
sampleWorkspace,
29+
sampleUsername,
30+
"http",
31+
"/path1/path2",
32+
);
33+
expect(forwarded).toEqual(
34+
"http://12345--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2",
35+
);
36+
});
37+
it("https, host, port, path and empty params", () => {
38+
const forwarded = portForwardURL(
39+
proxyHostWildcard,
40+
samplePort,
41+
sampleAgent,
42+
sampleWorkspace,
43+
sampleUsername,
44+
"https",
45+
"/path1/path2",
46+
"?",
47+
);
48+
expect(forwarded).toEqual(
49+
"http://12345s--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2?",
50+
);
51+
});
52+
it("http, host, port, path and query params", () => {
53+
const forwarded = portForwardURL(
54+
proxyHostWildcard,
55+
samplePort,
56+
sampleAgent,
57+
sampleWorkspace,
58+
sampleUsername,
59+
"http",
60+
"/path1/path2",
61+
"?key1=value1&key2=value2",
62+
);
63+
expect(forwarded).toEqual(
64+
"http://12345--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2?key1=value1&key2=value2",
65+
);
66+
});
67+
});

site/src/utils/portForward.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export const portForwardURL = (
77
workspaceName: string,
88
username: string,
99
protocol: WorkspaceAgentPortShareProtocol,
10+
pathname?: string,
11+
search?: string,
1012
): string => {
1113
const { location } = window;
1214
const suffix = protocol === "https" ? "s" : "";
@@ -15,7 +17,12 @@ export const portForwardURL = (
1517

1618
const baseUrl = `${location.protocol}//${host.replace("*", subdomain)}`;
1719
const url = new URL(baseUrl);
18-
20+
if (pathname) {
21+
url.pathname = pathname;
22+
}
23+
if (search) {
24+
url.search = search;
25+
}
1926
return url.toString();
2027
};
2128

@@ -63,7 +70,9 @@ export const openMaybePortForwardedURL = (
6370
workspaceName,
6471
username,
6572
url.protocol.replace(":", "") as WorkspaceAgentPortShareProtocol,
66-
) + url.pathname,
73+
url.pathname,
74+
url.search,
75+
),
6776
);
6877
} catch (ex) {
6978
open(uri);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy