Skip to content

Commit 5419f62

Browse files
authored
Handle ? in SSH config (#150)
1 parent 9dac78f commit 5419f62

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/sshSupport.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,31 @@ Host coder-vscode--*
4040
ProxyCommand: '/tmp/coder --header="X-FOO=bar" coder.dev',
4141
})
4242
})
43+
44+
it("handles ? wildcards", () => {
45+
const properties = computeSSHProperties(
46+
"coder-vscode--testing",
47+
`Host *
48+
StrictHostKeyChecking yes
49+
50+
Host i-???????? i-?????????????????
51+
User test
52+
53+
# --- START CODER VSCODE ---
54+
Host coder-v?ode--*
55+
StrictHostKeyChecking yes
56+
Another=false
57+
Host coder-v?code--*
58+
StrictHostKeyChecking no
59+
Another=true
60+
ProxyCommand=/tmp/coder --header="X-BAR=foo" coder.dev
61+
# --- END CODER VSCODE ---
62+
`,
63+
)
64+
65+
expect(properties).toEqual({
66+
Another: "true",
67+
StrictHostKeyChecking: "yes",
68+
ProxyCommand: '/tmp/coder --header="X-BAR=foo" coder.dev',
69+
})
70+
})

src/sshSupport.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ export function computeSSHProperties(host: string, config: string): Record<strin
8585
if (!config) {
8686
return
8787
}
88-
if (!new RegExp("^" + config?.Host.replace(/\*/g, ".*") + "$").test(host)) {
88+
// In OpenSSH * matches any number of characters and ? matches exactly one.
89+
if (!new RegExp("^" + config?.Host.replace(/\*/g, ".*").replace(/\?/g, ".") + "$").test(host)) {
8990
return
9091
}
9192
Object.assign(merged, config.properties)

0 commit comments

Comments
 (0)