anvilmcp: use single quotes for bash arg escaping

Prevents shell variable expansion in tool args. $VAR now stays
literal instead of expanding to empty string.
This commit is contained in:
Levi Neely 2026-03-06 15:03:26 +01:00
parent fc6cca01a8
commit bda779380e
1 changed files with 3 additions and 2 deletions

View File

@ -185,10 +185,11 @@ func handleToolCall(req MCPRequest) {
code = toolCode
// For bash with args, wrap script to receive positional params
if len(toolArgs) > 0 {
// Escape args for bash array
// Escape args for bash using single quotes (prevents all expansion)
var escaped []string
for _, arg := range toolArgs {
escaped = append(escaped, fmt.Sprintf("%q", arg))
// Replace ' with '\'' (end quote, escaped quote, start quote)
escaped = append(escaped, "'"+strings.ReplaceAll(arg, "'", "'\\''")+"'")
}
code = fmt.Sprintf("set -- %s\n%s", strings.Join(escaped, " "), code)
}