Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

chore: use some raw strings to reduce quoting (#9745)

Michael Bolin86a1e41f2ee8
diff --git a/codex-rs/core/src/bash.rs b/codex-rs/core/src/bash.rs
index 055e30d765..bb0ae7fe90 100644
--- a/codex-rs/core/src/bash.rs
+++ b/codex-rs/core/src/bash.rs
@@ -181,6 +181,7 @@ fn parse_double_quoted_string(node: Node, src: &str) -> Option<String> {
if node.kind() != "string" {
return None;
}
+
let mut cursor = node.walk();
for part in node.named_children(&mut cursor) {
if part.kind() != "string_content" {
@@ -198,6 +199,7 @@ fn parse_raw_string(node: Node, src: &str) -> Option<String> {
if node.kind() != "raw_string" {
return None;
}
+
let raw_string = node.utf8_text(src.as_bytes()).ok()?;
let stripped = raw_string
.strip_prefix('\'')
@@ -265,17 +267,20 @@ mod tests {
#[test]
fn accepts_mixed_quote_concatenation() {
- let cmds = parse_seq("echo \"/usr\"'/'\"local\"/bin").unwrap();
assert_eq!(
- cmds,
+ parse_seq(r#"echo "/usr"'/'"local"/bin"#).unwrap(),
+ vec![vec!["echo".to_string(), "/usr/local/bin".to_string()]]
+ );
+ assert_eq!(
+ parse_seq(r#"echo '/usr'"/"'local'/bin"#).unwrap(),
vec![vec!["echo".to_string(), "/usr/local/bin".to_string()]]
);
}
#[test]
fn rejects_double_quoted_strings_with_expansions() {
- assert!(parse_seq("echo \"hi ${USER}\"").is_none());
- assert!(parse_seq("echo \"$HOME\"").is_none());
+ assert!(parse_seq(r#"echo "hi ${USER}""#).is_none());
+ assert!(parse_seq(r#"echo "$HOME""#).is_none());
}
#[test]