- Notifications
You must be signed in to change notification settings - Fork35
Fix SetEnv SSH config parsing and accumulation#684
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
EhabY wants to merge2 commits intocoder:mainChoose a base branch fromEhabY:fix-setenv-ssh-config
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+219 −32
Open
Changes from1 commit
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
Fix SetEnv SSH config parsing and accumulation
- Add parseSshConfig function to correctly parse "SetEnv MY_VAR=value" (previously split on first "=" producing incorrect key/value)- Modify mergeSshConfigValues to concatenate SetEnv values instead of replacing, preserving the default CODER_SSH_SESSION_TYPE- Ignore empty SetEnv values to prevent accidentally clearing defaults
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commitd4f7eaa1b2bd98395a1823758629705e328e9e7c
There are no files selected for viewing
4 changes: 4 additions & 0 deletionsCHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionpackage.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
31 changes: 9 additions & 22 deletionssrc/remote/remote.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
63 changes: 57 additions & 6 deletionssrc/remote/sshConfig.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -36,10 +36,48 @@ const defaultFileSystem: FileSystem = { | ||
| writeFile, | ||
| }; | ||
| /** | ||
| * Parse an array of SSH config lines into a Record. | ||
| * Handles both "Key value" and "Key=value" formats. | ||
| * Accumulates SetEnv values since SSH allows multiple environment variables. | ||
| */ | ||
| export function parseSshConfig(lines: string[]): Record<string, string> { | ||
| return lines.reduce( | ||
| (acc, line) => { | ||
| // Match key pattern (same as VS Code settings: ^[a-zA-Z0-9-]+) | ||
| const keyMatch = line.match(/^[a-zA-Z0-9-]+/); | ||
| if (!keyMatch) { | ||
| return acc; // Malformed line | ||
| } | ||
| const key = keyMatch[0]; | ||
| const separator = line[key.length]; | ||
EhabY marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if (separator !== "=" && separator !== " ") { | ||
| return acc; // Malformed line | ||
| } | ||
| const value = line.slice(key.length + 1); | ||
| // Accumulate SetEnv values since there can be multiple. | ||
| if (key.toLowerCase() === "setenv") { | ||
| // Ignore empty SetEnv values | ||
| if (value !== "") { | ||
| const existing = acc["SetEnv"]; | ||
| acc["SetEnv"] = existing ? `${existing} ${value}` : ` ${value}`; | ||
| } | ||
| } else { | ||
| acc[key] = value; | ||
| } | ||
| return acc; | ||
| }, | ||
| {} as Record<string, string>, | ||
| ); | ||
| } | ||
| // mergeSSHConfigValues will take a given ssh config and merge it with the overrides | ||
| // provided. The merge handles key case insensitivity, so casing in the "key" does | ||
| // not matter. | ||
| export functionmergeSshConfigValues( | ||
| config: Record<string, string>, | ||
| overrides: Record<string, string>, | ||
| ): Record<string, string> { | ||
| @@ -62,11 +100,17 @@ export function mergeSSHConfigValues( | ||
| const value = overrides[correctCaseKey]; | ||
| delete caseInsensitiveOverrides[lower]; | ||
| // Special handling for SetEnv - concatenate values instead of replacing. | ||
| if (lower === "setenv") { | ||
| merged["SetEnv"] = `${config[key]}${value}`; | ||
EhabY marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| return; | ||
| } | ||
| // If the value is empty, do not add the key. It is being removed. | ||
| if (value !== "") { | ||
| merged[correctCaseKey] = value; | ||
| } | ||
| return; | ||
| } | ||
| // If no override, take the original value. | ||
| @@ -78,7 +122,14 @@ export function mergeSSHConfigValues( | ||
| // Add remaining overrides. | ||
| Object.keys(caseInsensitiveOverrides).forEach((lower) => { | ||
| const correctCaseKey = caseInsensitiveOverrides[lower]; | ||
| const value = overrides[correctCaseKey]; | ||
| // Special handling for SetEnv - concatenate if already exists | ||
| if (lower === "setenv" && merged["SetEnv"]) { | ||
| merged["SetEnv"] = `${merged["SetEnv"]}${value}`; | ||
EhabY marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } else { | ||
| merged[correctCaseKey] = value; | ||
| } | ||
| }); | ||
| return merged; | ||
| @@ -203,7 +254,7 @@ export class SSHConfig { | ||
| const lines = [this.startBlockComment(safeHostname), `Host ${Host}`]; | ||
| // configValues is the merged values of the defaults and the overrides. | ||
| const configValues =mergeSshConfigValues(otherValues, overrides || {}); | ||
| // keys is the sorted keys of the merged values. | ||
| const keys = ( | ||
145 changes: 143 additions & 2 deletionstest/unit/remote/sshConfig.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.