Skip to content

Commit c6bc40f

Browse files
committed
Allow any quoting for shell commands.
1 parent c578d1a commit c6bc40f

File tree

1 file changed

+20
-4
lines changed
  • crates/rb-cli/src/commands

1 file changed

+20
-4
lines changed

crates/rb-cli/src/commands/run.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,18 @@ pub fn run_command(
359359
fn parse_command(command: &str) -> Vec<String> {
360360
let mut parts = Vec::new();
361361
let mut current = String::new();
362-
let mut in_quotes = false;
362+
let mut in_double_quotes = false;
363+
let mut in_single_quotes = false;
363364

364365
for ch in command.chars() {
365366
match ch {
366-
'"' => {
367-
in_quotes = !in_quotes;
367+
'"' if !in_single_quotes => {
368+
in_double_quotes = !in_double_quotes;
368369
}
369-
' ' if !in_quotes => {
370+
'\'' if !in_double_quotes => {
371+
in_single_quotes = !in_single_quotes;
372+
}
373+
' ' if !in_double_quotes && !in_single_quotes => {
370374
if !current.is_empty() {
371375
parts.push(current.clone());
372376
current.clear();
@@ -431,6 +435,18 @@ mod tests {
431435
);
432436
}
433437

438+
#[test]
439+
fn test_parse_command_with_single_quotes() {
440+
assert_eq!(
441+
parse_command("ruby -e 'puts ARGV.join(\", \")'"),
442+
vec![
443+
"ruby".to_string(),
444+
"-e".to_string(),
445+
"puts ARGV.join(\", \")".to_string()
446+
]
447+
);
448+
}
449+
434450
#[test]
435451
fn test_parse_command_empty() {
436452
assert_eq!(parse_command(""), Vec::<String>::new());

0 commit comments

Comments
 (0)