MCPcopy Create free account
hub / github.com/AutoForgeAI/autoforge / split_command_segments

Function split_command_segments

security.py:142–169  ·  view source on GitHub ↗

Split a compound command into individual command segments. Handles command chaining (&&, ||, ;) but not pipes (those are single commands). Args: command_string: The full shell command Returns: List of individual command segments

(command_string: str)

Source from the content-addressed store, hash-verified

140
141
142def split_command_segments(command_string: str) -> list[str]:
143 """
144 Split a compound command into individual command segments.
145
146 Handles command chaining (&&, ||, ;) but not pipes (those are single commands).
147
148 Args:
149 command_string: The full shell command
150
151 Returns:
152 List of individual command segments
153 """
154 import re
155
156 # Split on && and || while preserving the ability to handle each segment
157 # This regex splits on && or || that aren't inside quotes
158 segments = re.split(r"\s*(?:&&|\|\|)\s*", command_string)
159
160 # Further split on semicolons
161 result = []
162 for segment in segments:
163 sub_segments = re.split(r'(?<!["\'])\s*;\s*(?!["\'])', segment)
164 for sub in sub_segments:
165 sub = sub.strip()
166 if sub:
167 result.append(sub)
168
169 return result
170
171
172def _extract_primary_command(segment: str) -> str | None:

Callers 1

bash_security_hookFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected