Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

fix(core) exec policy parsing 3 (#12485)

Dylan Hurd85b00ae8de23
diff --git a/codex-rs/shell-command/src/bash.rs b/codex-rs/shell-command/src/bash.rs
index 770ff4795b..2fe299108c 100644
--- a/codex-rs/shell-command/src/bash.rs
+++ b/codex-rs/shell-command/src/bash.rs
@@ -128,6 +128,9 @@ pub fn parse_shell_lc_single_command_prefix(command: &[String]) -> Option<Vec<St
if root.has_error() {
return None;
}
+ if !has_named_descendant_kind(root, "heredoc_redirect") {
+ return None;
+ }
let command_node = find_single_command_node(root)?;
parse_heredoc_command_words(command_node, script)
@@ -265,6 +268,20 @@ fn find_single_command_node(root: Node<'_>) -> Option<Node<'_>> {
single_command
}
+fn has_named_descendant_kind(node: Node<'_>, kind: &str) -> bool {
+ let mut stack = vec![node];
+ while let Some(current) = stack.pop() {
+ if current.kind() == kind {
+ return true;
+ }
+ let mut cursor = current.walk();
+ for child in current.named_children(&mut cursor) {
+ stack.push(child);
+ }
+ }
+ false
+}
+
fn parse_double_quoted_string(node: Node, src: &str) -> Option<String> {
if node.kind() != "string" {
return None;
@@ -515,10 +532,7 @@ mod tests {
"-lc".to_string(),
"echo hello > /tmp/out.txt".to_string(),
];
- assert_eq!(
- parse_shell_lc_single_command_prefix(&command),
- Some(vec!["echo".to_string(), "hello".to_string()])
- );
+ assert_eq!(parse_shell_lc_single_command_prefix(&command), None);
}
#[test]