From 0e6144567c4d6d479f9ac1e851440283242a9ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Daron?= Date: Mon, 15 Jul 2024 10:07:19 +0200 Subject: [PATCH] fixing nested expansions --- helix-core/src/shellwords.rs | 11 +++++++++-- helix-term/tests/test/commands/variable_expansion.rs | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/helix-core/src/shellwords.rs b/helix-core/src/shellwords.rs index 2a1cb0801..0a8689a8b 100644 --- a/helix-core/src/shellwords.rs +++ b/helix-core/src/shellwords.rs @@ -46,7 +46,7 @@ impl<'a> From<&'a str> for Shellwords<'a> { let mut parts = Vec::new(); let mut escaped = String::with_capacity(input.len()); let mut inside_variable_expansion = false; - + let mut nested_variable_expansion_count = 0; let mut part_start = 0; let mut unescaped_start = 0; let mut end = 0; @@ -57,18 +57,25 @@ impl<'a> From<&'a str> for Shellwords<'a> { //%sh{this "should" be escaped} if let Some(t) = input.get(i + 1..i + 3) { if t == "sh" { + nested_variable_expansion_count += 1; inside_variable_expansion = true; } } //%{this "should" be escaped} if let Some(t) = input.get(i + 1..i + 2) { if t == "{" { + nested_variable_expansion_count += 1; inside_variable_expansion = true; } } } } else if c == '}' { - inside_variable_expansion = false; + nested_variable_expansion_count -= 1; + if nested_variable_expansion_count == 0 { + inside_variable_expansion = false; + } + } else if c == '{' { + nested_variable_expansion_count += 1; } state = if !inside_variable_expansion { diff --git a/helix-term/tests/test/commands/variable_expansion.rs b/helix-term/tests/test/commands/variable_expansion.rs index a0935c426..1d644cb6c 100644 --- a/helix-term/tests/test/commands/variable_expansion.rs +++ b/helix-term/tests/test/commands/variable_expansion.rs @@ -17,6 +17,7 @@ async fn test_variable_expansion() -> anyhow::Result<()> { false, ) .await?; + let mut app = AppBuilder::new().build()?; let mut app = AppBuilder::new().build()?;