Skip to content

Commit 58de3a2

Browse files
fix(contracts): Open in VS Code keeps a plus in the SSH username
Remote-SSH splits the decoded ssh-remote authority on "+", so a login like [email protected] connected to host "vm". Destinations that contain "+" now use Remote-SSH's hex-encoded JSON {hostName,user} form. Fixes #34565 AI-assisted; verified with the tests and tools listed above.
1 parent cb94ea2 commit 58de3a2

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎packages/contracts/src/editor.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,16 @@ export const buildRemoteOpenUrl = (input: {
227227
return `${scheme}://ssh/${zedDestination}${encodedZedPath}`;
228228
}
229229
const encodedPath = rootedPath.split("/").map(encodeURIComponent).join("/");
230-
const destination = input.username === undefined ? input.host : `${input.username}@${input.host}`;
230+
const plainDestination =
231+
input.username === undefined ? input.host : `${input.username}@${input.host}`;
232+
// Remote-SSH splits the decoded authority on "+", so a destination containing one must use its
233+
// hex-encoded JSON form instead.
234+
const destination = plainDestination.includes("+")
235+
? Array.from(
236+
new TextEncoder().encode(JSON.stringify({ hostName: input.host, user: input.username })),
237+
(byte) => byte.toString(16).padStart(2, "0"),
238+
).join("")
239+
: plainDestination;
231240
// VS Code opens a bare vscode-remote path as a folder; a trailing position makes it open the file.
232241
return `${scheme}://vscode-remote/ssh-remote+${encodeURIComponent(destination)}${encodedPath}${input.isFile ? ":1:1" : ""}`;
233242
};

0 commit comments

Comments
 (0)