refactor: simplify ampersand segment check

Maintainer edit: keep the single-ampersand guard behavior, but fold the redirect exceptions into one condition instead of carrying temporary previous/next character variables.
This commit is contained in:
chengyongru
2026-07-21 13:50:24 +08:00
committed by Xubin Ren
parent 12c52c11d3
commit ab6ceef1a1
+4 -5
View File
@@ -879,11 +879,10 @@ class ExecTool(Tool):
if paren_depth == 0: if paren_depth == 0:
if command.startswith(("&&", "||"), i): if command.startswith(("&&", "||"), i):
operator_len = 2 operator_len = 2
elif ch == "&": elif ch == "&" and not (
prev_ch = command[i - 1] if i > 0 else "" (i > 0 and command[i - 1] in "<>") or command.startswith("&>", i)
next_ch = command[i + 1] if i + 1 < len(command) else "" ):
if prev_ch not in {"<", ">"} and next_ch != ">": operator_len = 1
operator_len = 1
elif ch in {";", "|"}: elif ch in {";", "|"}:
operator_len = 1 operator_len = 1