Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/cortex-commands/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ pub fn substitute_placeholders(template: &str, arguments: &str) -> String {
// Find the highest numbered placeholder
let max_placeholder = find_max_placeholder(&result);

// Replace numbered placeholders
for i in 1..=max_placeholder {
// Replace longer placeholders first so `$1` does not corrupt `$10`.
for i in (1..=max_placeholder).rev() {
let placeholder = format!("${i}");
let replacement = if i == max_placeholder {
// Last placeholder captures all remaining arguments
Expand Down Expand Up @@ -374,6 +374,17 @@ No closing delimiter"#;
assert_eq!(result, "A: only_one, B: , C: ");
}

#[test]
fn test_substitute_two_digit_placeholders_before_prefixes() {
let template = "Run $1 and item $10";
let result = substitute_placeholders(
template,
"alpha beta gamma delta epsilon zeta eta theta iota kappa",
);

assert_eq!(result, "Run alpha and item kappa");
}

#[test]
fn test_command_parse() {
let content = r#"---
Expand Down