From 63f6cfec5ba3932abf875ee253ade610ca6f0362 Mon Sep 17 00:00:00 2001 From: Cyrus Date: Wed, 12 Aug 2026 20:08:36 +0800 Subject: [PATCH] Split the doubled and plain backslash cases in the quoting test escapeArg only doubles a backslash that precedes a quote or ends the argument, the same rule as syscall.EscapeArg, and @ is not a cmd metacharacter so it is not caret-escaped. The Windows expectations here still asked for both. Checked by round-tripping each entry through cmd.exe into a program's argv: all ten come back byte for byte. --- src/terminal_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/terminal_test.go b/src/terminal_test.go index 117f0006..8607f870 100644 --- a/src/terminal_test.go +++ b/src/terminal_test.go @@ -251,9 +251,9 @@ func TestReplacePlaceholder(t *testing.T) { } func TestQuoteEntry(t *testing.T) { - type quotes struct{ E, O, SQ, DQ, BS string } // standalone escape, outer, single and double quotes, backslash - unixStyle := quotes{``, `'`, `'\''`, `"`, `\`} - windowsStyle := quotes{`^`, `^"`, `'`, `\^"`, `\\`} + type quotes struct{ E, O, SQ, DQ, BS, PB string } // standalone escape, outer, single and double quotes, doubled and plain backslash + unixStyle := quotes{``, `'`, `'\''`, `"`, `\`, `\`} + windowsStyle := quotes{`^`, `^"`, `'`, `\^"`, `\\`, `\`} var effectiveStyle quotes exec := util.NewExecutor("") @@ -280,13 +280,13 @@ func TestQuoteEntry(t *testing.T) { `>`: `{{.O}}{{.E}}>{{.O}}`, `(`: `{{.O}}{{.E}}({{.O}}`, `)`: `{{.O}}{{.E}}){{.O}}`, - `@`: `{{.O}}{{.E}}@{{.O}}`, + `@`: `{{.O}}@{{.O}}`, `^`: `{{.O}}{{.E}}^{{.O}}`, `%`: `{{.O}}{{.E}}%{{.O}}`, `!`: `{{.O}}{{.E}}!{{.O}}`, `%USERPROFILE%`: `{{.O}}{{.E}}%USERPROFILE{{.E}}%{{.O}}`, - `C:\Program Files (x86)\`: `{{.O}}C:{{.BS}}Program Files {{.E}}(x86{{.E}}){{.BS}}{{.O}}`, - `"C:\Program Files"`: `{{.O}}{{.DQ}}C:{{.BS}}Program Files{{.DQ}}{{.O}}`, + `C:\Program Files (x86)\`: `{{.O}}C:{{.PB}}Program Files {{.E}}(x86{{.E}}){{.BS}}{{.O}}`, + `"C:\Program Files"`: `{{.O}}{{.DQ}}C:{{.PB}}Program Files{{.DQ}}{{.O}}`, } for input, expected := range tests {