Escape backticks and dollar signs in quoteForShell (#777)

* Escape backticks and dollar signs in quoteForShell

* Sync embedded formulas with .beads/formulas
This commit is contained in:
Steve Whittaker
2026-01-20 15:11:00 -06:00
committed by GitHub
parent 55a3b9858a
commit 6966eb4c28
4 changed files with 83 additions and 43 deletions

View File

@@ -580,9 +580,15 @@ func defaultInstructionsFile(provider string) string {
// quoteForShell quotes a string for safe shell usage.
func quoteForShell(s string) string {
// Simple quoting: wrap in double quotes, escape internal quotes
// Wrap in double quotes, escaping characters that are special in double-quoted strings:
// - backslash (escape character)
// - double quote (string delimiter)
// - backtick (command substitution)
// - dollar sign (variable expansion)
escaped := strings.ReplaceAll(s, `\`, `\\`)
escaped = strings.ReplaceAll(escaped, `"`, `\"`)
escaped = strings.ReplaceAll(escaped, "`", "\\`")
escaped = strings.ReplaceAll(escaped, "$", `\$`)
return `"` + escaped + `"`
}