Keep completion words out of shell evaluation
This commit is contained in:
@@ -161,6 +161,32 @@ sys.stdout.write(os.environ['PROBE_REPLY'])
|
||||
}
|
||||
})
|
||||
}
|
||||
if shell == "bash" || shell == "zsh" {
|
||||
for _, tc := range []struct{ name, line string }{
|
||||
{"quoted", `probe --format '-$(touch sentinel)=x'`},
|
||||
{"escaped", `probe --format -\$\(touch\ sentinel\)=x`},
|
||||
} {
|
||||
t.Run(shell+"/literal query/"+tc.name, func(t *testing.T) {
|
||||
log := filepath.Join(dir, "query-log")
|
||||
if err := os.WriteFile(log, nil, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd := exec.Command("python3", "testdata/completion_terminal.py", shell, script, tc.line)
|
||||
cmd.Env = append(os.Environ(), "PATH="+dir+string(os.PathListSeparator)+os.Getenv("PATH"), "HOME="+dir, "TERM=xterm", "PROBE_DIR="+dir, "PROBE_LOG="+log, "PROBE_TAB_ONLY=1", "PROBE_REPLY=:4\n")
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("tab-only completion: %v\n%s", err, out)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "sentinel")); !os.IsNotExist(err) {
|
||||
t.Fatalf("completion executed literal input: %v", err)
|
||||
}
|
||||
got, err := os.ReadFile(log)
|
||||
if err != nil || !strings.Contains(string(got), `["__complete", "--format", "-$(touch sentinel)=x"]`) {
|
||||
t.Fatalf("literal query was not preserved: %q, %v", got, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for _, executable := range []string{"probe.app", "café"} {
|
||||
t.Run(shell+"/executable "+executable, func(t *testing.T) {
|
||||
var generated bytes.Buffer
|
||||
|
||||
Reference in New Issue
Block a user