@@ -193,16 +193,17 @@ func Test_sshConfigMatchExecEscape(t *testing.T) {
193
193
t .Parallel ()
194
194
195
195
tests := []struct {
196
- name string
197
- path string
198
- wantErr bool
196
+ name string
197
+ path string
198
+ wantErrOther bool
199
+ wantErrWindows bool
199
200
}{
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 },
206
207
}
207
208
// nolint:paralleltest // Fixes a flake
208
209
for _ , tt := range tests {
@@ -214,24 +215,26 @@ func Test_sshConfigMatchExecEscape(t *testing.T) {
214
215
if runtime .GOOS == "windows" {
215
216
cmd = "cmd.exe"
216
217
arg = "/c"
217
- contents = []byte ("echo yay\n " )
218
+ contents = []byte ("@ echo yay\n " )
218
219
}
219
220
220
221
dir := filepath .Join (t .TempDir (), tt .path )
221
- err := os .MkdirAll (dir , 0o755 )
222
- require .NoError (t , err )
223
222
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
-
228
223
escaped , err := sshConfigMatchExecEscape (bin )
229
- if tt .wantErr {
224
+ if ( runtime . GOOS == "windows" && tt .wantErrWindows ) || ( runtime . GOOS != "windows" && tt . wantErrOther ) {
230
225
require .Error (t , err )
231
226
return
232
227
}
233
228
require .NoError (t , err )
234
229
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 , "%%" , "%" )
235
238
b , err := exec .Command (cmd , arg , escaped ).CombinedOutput () //nolint:gosec
236
239
require .NoError (t , err )
237
240
got := strings .TrimSpace (string (b ))
0 commit comments