Skip to content

fix: use url-parse for url construction #15670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Nov 27, 2024
Prev Previous commit
Next Next commit
fix: fix incomplete string escaping in portforward URL
  • Loading branch information
sreya committed Nov 26, 2024
commit 27666578afd75632f9a2bbfa9fc454b8c27fb1a4
7 changes: 6 additions & 1 deletion site/src/utils/portForward.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { WorkspaceAgentPortShareProtocol } from "api/typesGenerated";
import URLParse from 'url-parse';

export const portForwardURL = (
host: string,
Expand All @@ -12,7 +13,11 @@ export const portForwardURL = (
const suffix = protocol === "https" ? "s" : "";

const subdomain = `${port}${suffix}--${agentName}--${workspaceName}--${username}`;
return `${location.protocol}//${host}`.replace("*", subdomain);
const url = new URLParse('');
url.set('protocol', location.protocol);
url.set('hostname', host.replace('*', subdomain));

return url.toString();
};

// openMaybePortForwardedURL tries to open the provided URI through the
Expand Down