Skip to content

Commit

Permalink
Merge pull request #23 from Ph0enixKM/A32
Browse files Browse the repository at this point in the history
A32 Fix: Nested command evaluation
  • Loading branch information
Ph0enixKM authored Aug 28, 2022
2 parents 1e6157c + 430cbe4 commit fcaee99
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ mod tests {
assert_eq!(cli.test_eval(code).trim(), "Hello World");
}

#[test]
fn command_inception() {
let cli = CLI::new();
let code = "
${${${$echo Hello World$}$}$}$
";
assert_eq!(cli.test_eval(code).trim(), "Hello World");
}

#[test]
fn comment() {
let cli = CLI::new();
Expand Down
8 changes: 7 additions & 1 deletion src/modules/command/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ impl TranslateModule for CommandStatement {
let interps = self.interps.iter()
.map(|item| item.translate(meta))
.collect::<Vec<String>>();
translate_interpolated_region(self.strings.clone(), interps, false)
let mut translation = translate_interpolated_region(self.strings.clone(), interps, false);
// Strip down all the inner command interpolations [A32]
while translation.starts_with("$(") {
let end = translation.len() - 1;
translation = translation.get(2..end).unwrap().to_string();
}
translation
}
}

0 comments on commit fcaee99

Please sign in to comment.