@@ -193,16 +193,17 @@ func Test_sshConfigMatchExecEscape(t *testing.T) {
193193 t .Parallel ()
194194
195195 tests := []struct {
196- name string
197- path string
198- wantErr bool
196+ name string
197+ path string
198+ wantErrOther bool
199+ wantErrWindows bool
199200 }{
200- {"no spaces" , "simple" , false },
201- {"spaces" , "path with spaces" , false },
202- {"quotes fails " , "path with \" quotes\" " , true },
203- {"backslashes" , "path with \\ backslashes" , false },
204- {"tabs" , "path with \t tabs" , false },
205- {"newline fails" , "path with \n newline" , true },
201+ {"no spaces" , "simple" , false , false },
202+ {"spaces" , "path with spaces" , false , false },
203+ {"quotes" , "path with \" quotes\" " , false , true },
204+ {"backslashes" , "path with\\ backslashes" , false , false },
205+ {"tabs" , "path with \t tabs" , false , true },
206+ {"newline fails" , "path with \n newline" , true , true },
206207 }
207208 // nolint:paralleltest // Fixes a flake
208209 for _ , tt := range tests {
@@ -214,24 +215,26 @@ func Test_sshConfigMatchExecEscape(t *testing.T) {
214215 if runtime .GOOS == "windows" {
215216 cmd = "cmd.exe"
216217 arg = "/c"
217- contents = []byte ("echo yay\n " )
218+ contents = []byte ("@ echo yay\n " )
218219 }
219220
220221 dir := filepath .Join (t .TempDir (), tt .path )
221- err := os .MkdirAll (dir , 0o755 )
222- require .NoError (t , err )
223222 bin := filepath .Join (dir , "coder.bat" ) // Windows will treat it as batch, Linux doesn't care
224-
225- err = os .WriteFile (bin , contents , 0o755 ) //nolint:gosec
226- require .NoError (t , err )
227-
228223 escaped , err := sshConfigMatchExecEscape (bin )
229- if tt .wantErr {
224+ if ( runtime . GOOS == "windows" && tt .wantErrWindows ) || ( runtime . GOOS != "windows" && tt . wantErrOther ) {
230225 require .Error (t , err )
231226 return
232227 }
233228 require .NoError (t , err )
234229
230+ err = os .MkdirAll (dir , 0o755 )
231+ require .NoError (t , err )
232+
233+ err = os .WriteFile (bin , contents , 0o755 ) //nolint:gosec
234+ require .NoError (t , err )
235+
236+ // OpenSSH processes %% escape sequences into %
237+ escaped = strings .ReplaceAll (escaped , "%%" , "%" )
235238 b , err := exec .Command (cmd , arg , escaped ).CombinedOutput () //nolint:gosec
236239 require .NoError (t , err )
237240 got := strings .TrimSpace (string (b ))
0 commit comments