mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
fix bash commands being incorrectly quoted in display (#2313)
The "display format" of commands was sometimes producing incorrect quoting like `echo foo '>' bar`, which is importantly different from the actual command that was being run. This refactors ParsedCommand to have a string in `cmd` instead of a vec, as a `vec` can't accurately capture a full command.
This commit is contained in:
committed by
GitHub
Unverified
parent
20cd61e2a4
commit
7038827bf4
+280
-275
File diff suppressed because it is too large
Load Diff
@@ -206,7 +206,7 @@ fn exec_history_cell_shows_working_then_completed() {
|
||||
command: vec!["bash".into(), "-lc".into(), "echo done".into()],
|
||||
cwd: std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")),
|
||||
parsed_cmd: vec![codex_core::parse_command::ParsedCommand::Unknown {
|
||||
cmd: vec!["echo".into(), "done".into()],
|
||||
cmd: "echo done".into(),
|
||||
}],
|
||||
}),
|
||||
});
|
||||
@@ -248,7 +248,7 @@ fn exec_history_cell_shows_working_then_failed() {
|
||||
command: vec!["bash".into(), "-lc".into(), "false".into()],
|
||||
cwd: std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")),
|
||||
parsed_cmd: vec![codex_core::parse_command::ParsedCommand::Unknown {
|
||||
cmd: vec!["false".into()],
|
||||
cmd: "false".into(),
|
||||
}],
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -248,18 +248,19 @@ fn new_parsed_command(
|
||||
ParsedCommand::Read { name, .. } => format!("π {name}"),
|
||||
ParsedCommand::ListFiles { cmd, path } => match path {
|
||||
Some(p) => format!("π {p}"),
|
||||
None => format!("π {}", shlex_join_safe(cmd)),
|
||||
None => format!("π {cmd}"),
|
||||
},
|
||||
ParsedCommand::Search { query, path, cmd } => match (query, path) {
|
||||
(Some(q), Some(p)) => format!("π {q} in {p}"),
|
||||
(Some(q), None) => format!("π {q}"),
|
||||
(None, Some(p)) => format!("π {p}"),
|
||||
(None, None) => format!("π {}", shlex_join_safe(cmd)),
|
||||
(None, None) => format!("π {cmd}"),
|
||||
},
|
||||
ParsedCommand::Format { .. } => "β¨ Formatting".to_string(),
|
||||
ParsedCommand::Test { cmd } => format!("π§ͺ {}", shlex_join_safe(cmd)),
|
||||
ParsedCommand::Lint { cmd, .. } => format!("π§Ή {}", shlex_join_safe(cmd)),
|
||||
ParsedCommand::Unknown { cmd } => format!("β¨οΈ {}", shlex_join_safe(cmd)),
|
||||
ParsedCommand::Test { cmd } => format!("π§ͺ {cmd}"),
|
||||
ParsedCommand::Lint { cmd, .. } => format!("π§Ή {cmd}"),
|
||||
ParsedCommand::Unknown { cmd } => format!("β¨οΈ {cmd}"),
|
||||
ParsedCommand::Noop { cmd } => format!("π {cmd}"),
|
||||
};
|
||||
|
||||
let first_prefix = if i == 0 { " β " } else { " " };
|
||||
@@ -856,13 +857,6 @@ fn format_mcp_invocation<'a>(invocation: McpInvocation) -> Line<'a> {
|
||||
Line::from(invocation_spans)
|
||||
}
|
||||
|
||||
fn shlex_join_safe(command: &[String]) -> String {
|
||||
match shlex::try_join(command.iter().map(|s| s.as_str())) {
|
||||
Ok(cmd) => cmd,
|
||||
Err(_) => command.join(" "),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -870,7 +864,7 @@ mod tests {
|
||||
#[test]
|
||||
fn parsed_command_with_newlines_starts_each_line_at_origin() {
|
||||
let parsed = vec![ParsedCommand::Unknown {
|
||||
cmd: vec!["printf".into(), "foo\nbar".into()],
|
||||
cmd: "printf 'foo\nbar'".to_string(),
|
||||
}];
|
||||
let lines = exec_command_lines(&[], &parsed, None);
|
||||
assert!(lines.len() >= 3);
|
||||
|
||||
Reference in New Issue
Block a user