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:
parent
fc6cca01a8
commit
bda779380e
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue