fix: treat single ampersand as shell segment

Maintainer edit: single '&' backgrounds the preceding command and starts another top-level shell segment, so allowPatterns must split it the same way as ';', '|', '&&', and '||'. Keep fd redirections such as 2>&1 and &> intact.
This commit is contained in:
chengyongru
2026-07-21 13:50:24 +08:00
committed by Xubin Ren
parent f4a7079e65
commit 12c52c11d3
2 changed files with 22 additions and 0 deletions
+5
View File
@@ -879,6 +879,11 @@ class ExecTool(Tool):
if paren_depth == 0:
if command.startswith(("&&", "||"), i):
operator_len = 2
elif ch == "&":
prev_ch = command[i - 1] if i > 0 else ""
next_ch = command[i + 1] if i + 1 < len(command) else ""
if prev_ch not in {"<", ">"} and next_ch != ">":
operator_len = 1
elif ch in {";", "|"}:
operator_len = 1