Skip to content

Commit 92e8b1d

Browse files
jeanp413mustard-mh
authored andcommitted
return URL in resolveExternalUri
1 parent 64d45b9 commit 92e8b1d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/vs/gitpod/browser/workbench/workbench.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -855,19 +855,21 @@ async function doStart(): Promise<IDisposable> {
855855
if (!localhost) {
856856
return uri;
857857
}
858-
let externalEndpoint: URI;
858+
let externalEndpoint: URL;
859859
const tunnel = tunnels.get(localhost.port);
860860
if (tunnel) {
861-
externalEndpoint = URI.parse('http://localhost:' + tunnel.status.localPort);
861+
externalEndpoint = new URL('http://localhost:' + tunnel.status.localPort);
862862
} else {
863863
const publicUrl = (await vscode.commands.executeCommand('gitpod.resolveExternalPort', localhost.port)) as any as string;
864-
externalEndpoint = URI.parse(publicUrl);
864+
externalEndpoint = new URL(publicUrl);
865865
}
866-
return externalEndpoint.with({
867-
path: uri.path,
868-
query: uri.query,
869-
fragment: uri.fragment
870-
});
866+
externalEndpoint.pathname = uri.path.split('/').map(s => encodeURIComponent(s)).join('/');
867+
externalEndpoint.hash = encodeURIComponent(uri.fragment);
868+
// vscode uri is so buggy that if the query part of a url contains percent encoded '=' or '&', it will decode it internally and the url will be invalid forever
869+
// using /=(.*)/s we can split only on the first ocurrence of '=' if the value also contains a '='
870+
// sadly not the case if the value contains '&' as it's possible it could signal another query param
871+
uri.query.split('&').map(s => s.split(/=(.*)/s)).forEach(([k, v]) => !!k && externalEndpoint.searchParams.append(k.replaceAll('+', ' '), v?.replaceAll('+', ' ') || ''));
872+
return externalEndpoint;
871873
},
872874
homeIndicator: {
873875
href: info.gitpodHost,

0 commit comments

Comments
 (0)