Skip to content

fix: SSHConfig: check for multiple start/end blocks #510

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 8 commits into from
May 23, 2025

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented May 20, 2025

Relates to #504

What this does:

Ports over the existing checks in coder config-ssh to handle malformed blocks.

Now, if your SSH config is malformed, you will see an error similar to the below upon attempting to connect:

  • If one of the automatically generated blocks is missing a start or end comment, you will see the below error:
    Screenshot 2025-05-21 at 17 15 04

  • If there is more than one block with a given label, you will see the below error:
    Screenshot 2025-05-21 at 17 14 39

In both cases, it will unfortunately be necessary to edit the SSH config and fix the issue manually.

@johnstcn johnstcn requested review from mafredri and code-asher May 20, 2025 16:41
@johnstcn johnstcn self-assigned this May 20, 2025
@johnstcn johnstcn force-pushed the cj/config-ssh/handle-malformed branch from 09777c5 to eda19a2 Compare May 20, 2025 17:03
@johnstcn johnstcn requested a review from bcpeinhardt May 20, 2025 17:04
Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestion but otherwise LGTM 👍🏻

count++
pos = haystack.indexOf(needle, pos + needle.length)
}
return count
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be simplified, like so?

return [...haystack.matchAll(needle)].length

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks way better, but matchAll wants a RegExp, which means needle would need to be properly un-escaped first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, forgot not all these methods are string | RegExp. That can be simply amended with RegExp.escape(needle).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only available in Node 24 and current version of VSCode is on 23.11.0 if I'm not mistaken 🥲

@bcpeinhardt
Copy link
Collaborator

Note to self: add changelog updates in separate PR so we don't force reapproval.

@bcpeinhardt bcpeinhardt merged commit 84acd8c into main May 23, 2025
2 checks passed
@bcpeinhardt bcpeinhardt deleted the cj/config-ssh/handle-malformed branch May 23, 2025 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants