From e86c5106bcfd04e4ef400cb1ca4befda8e1bcd2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 29 Jan 2025 10:53:54 -0700 Subject: [PATCH 1/8] Preserve space in variables --- crates/deno_task_shell/src/shell/execute.rs | 7 ++++++- crates/deno_task_shell/src/shell/types.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/deno_task_shell/src/shell/execute.rs b/crates/deno_task_shell/src/shell/execute.rs index 8180eac..2e82b0c 100644 --- a/crates/deno_task_shell/src/shell/execute.rs +++ b/crates/deno_task_shell/src/shell/execute.rs @@ -35,6 +35,7 @@ use crate::shell::types::FutureExecuteResult; use crate::shell::types::ShellPipeReader; use crate::shell::types::ShellPipeWriter; use crate::shell::types::ShellState; +use crate::shell::types::TextPart::Text as OtherText; use crate::parser::Arithmetic; use crate::parser::ArithmeticPart; @@ -1470,7 +1471,11 @@ fn evaluate_word_parts( } else if let Some(val) = state.get_var(&name).map(|v| v.to_string()) { - Ok(Some(val.into())) + let mut t: Text = val.clone().into(); + if val.ends_with(' ') { + t.parts.push(OtherText(" ".to_string())); + } + Ok(Some(t)) } else { Err(miette::miette!("Undefined variable: {}", name)) } diff --git a/crates/deno_task_shell/src/shell/types.rs b/crates/deno_task_shell/src/shell/types.rs index 3e6cf53..8c4d0f9 100644 --- a/crates/deno_task_shell/src/shell/types.rs +++ b/crates/deno_task_shell/src/shell/types.rs @@ -1305,7 +1305,7 @@ impl TextPart { #[derive(Debug, Clone)] pub struct Text { - parts: Vec, + pub parts: Vec, } impl Text { From 6ffec5444683e1fed34fab91277c893f489e7f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 29 Jan 2025 11:06:50 -0700 Subject: [PATCH 2/8] Keep all spaces --- crates/deno_task_shell/src/shell/execute.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/deno_task_shell/src/shell/execute.rs b/crates/deno_task_shell/src/shell/execute.rs index 2e82b0c..850fb39 100644 --- a/crates/deno_task_shell/src/shell/execute.rs +++ b/crates/deno_task_shell/src/shell/execute.rs @@ -1471,10 +1471,8 @@ fn evaluate_word_parts( } else if let Some(val) = state.get_var(&name).map(|v| v.to_string()) { - let mut t: Text = val.clone().into(); - if val.ends_with(' ') { - t.parts.push(OtherText(" ".to_string())); - } + let mut t: Text = Text::new([].to_vec()); + t.parts.push(OtherText(val.clone().to_string())); Ok(Some(t)) } else { Err(miette::miette!("Undefined variable: {}", name)) From c643afdfb4fb22e58cf6cf2254a4b178f24a76ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 29 Jan 2025 11:11:42 -0700 Subject: [PATCH 3/8] Fix a test (the test was wrong) --- crates/tests/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tests/src/lib.rs b/crates/tests/src/lib.rs index a53033b..409ceb9 100644 --- a/crates/tests/src/lib.rs +++ b/crates/tests/src/lib.rs @@ -53,7 +53,7 @@ async fn commands() { TestBuilder::new() .command(r#"TEST="1 2" ; echo $TEST"#) - .assert_stdout("1 2\n") + .assert_stdout("1 2\n") .run() .await; From 428c64234d2ee58e1cbcdc606734c1ff105a8979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 29 Jan 2025 16:47:39 -0700 Subject: [PATCH 4/8] Simplify --- crates/deno_task_shell/src/shell/execute.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/deno_task_shell/src/shell/execute.rs b/crates/deno_task_shell/src/shell/execute.rs index 850fb39..7b64437 100644 --- a/crates/deno_task_shell/src/shell/execute.rs +++ b/crates/deno_task_shell/src/shell/execute.rs @@ -1471,8 +1471,7 @@ fn evaluate_word_parts( } else if let Some(val) = state.get_var(&name).map(|v| v.to_string()) { - let mut t: Text = Text::new([].to_vec()); - t.parts.push(OtherText(val.clone().to_string())); + let t: Text = Text::new([OtherText(val.clone().to_string())].to_vec()); Ok(Some(t)) } else { Err(miette::miette!("Undefined variable: {}", name)) From 36eb5568d75c92b893c7cfb184ef6c2da101d536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 29 Jan 2025 17:03:19 -0700 Subject: [PATCH 5/8] Also fix ${PS1:-} --- crates/deno_task_shell/src/shell/execute.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/deno_task_shell/src/shell/execute.rs b/crates/deno_task_shell/src/shell/execute.rs index 7b64437..83f8a87 100644 --- a/crates/deno_task_shell/src/shell/execute.rs +++ b/crates/deno_task_shell/src/shell/execute.rs @@ -1240,7 +1240,10 @@ impl VariableModifier { match self { VariableModifier::DefaultValue(default_value) => { match state.get_var(name) { - Some(v) => Ok((v.clone().into(), None)), + Some(v) => { + let t: Text = Text::new([OtherText(v.clone().to_string())].to_vec()); + Ok((t, None)) + }, None => { let v = evaluate_word(default_value.clone(), state, stdin, stderr) .await From d2f8447008183a602235eae43fdee77502825b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 29 Jan 2025 17:04:44 -0700 Subject: [PATCH 6/8] cargo fmt --- crates/deno_task_shell/src/shell/execute.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/deno_task_shell/src/shell/execute.rs b/crates/deno_task_shell/src/shell/execute.rs index 83f8a87..36f3231 100644 --- a/crates/deno_task_shell/src/shell/execute.rs +++ b/crates/deno_task_shell/src/shell/execute.rs @@ -1241,9 +1241,10 @@ impl VariableModifier { VariableModifier::DefaultValue(default_value) => { match state.get_var(name) { Some(v) => { - let t: Text = Text::new([OtherText(v.clone().to_string())].to_vec()); + let t: Text = + Text::new([OtherText(v.clone().to_string())].to_vec()); Ok((t, None)) - }, + } None => { let v = evaluate_word(default_value.clone(), state, stdin, stderr) .await @@ -1474,7 +1475,8 @@ fn evaluate_word_parts( } else if let Some(val) = state.get_var(&name).map(|v| v.to_string()) { - let t: Text = Text::new([OtherText(val.clone().to_string())].to_vec()); + let t: Text = + Text::new([OtherText(val.clone().to_string())].to_vec()); Ok(Some(t)) } else { Err(miette::miette!("Undefined variable: {}", name)) From 929af3d1c49ff89505c7de426ba12caf2d38bad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 29 Jan 2025 17:06:27 -0700 Subject: [PATCH 7/8] Remove the pub hack --- crates/deno_task_shell/src/shell/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/deno_task_shell/src/shell/types.rs b/crates/deno_task_shell/src/shell/types.rs index 8c4d0f9..3e6cf53 100644 --- a/crates/deno_task_shell/src/shell/types.rs +++ b/crates/deno_task_shell/src/shell/types.rs @@ -1305,7 +1305,7 @@ impl TextPart { #[derive(Debug, Clone)] pub struct Text { - pub parts: Vec, + parts: Vec, } impl Text { From 1c0da61d283dd8d29917be69dfd1b55741cc1af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 29 Jan 2025 17:14:46 -0700 Subject: [PATCH 8/8] Add a test for ${TEST:-} --- crates/tests/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/tests/src/lib.rs b/crates/tests/src/lib.rs index 409ceb9..b66001a 100644 --- a/crates/tests/src/lib.rs +++ b/crates/tests/src/lib.rs @@ -57,6 +57,12 @@ async fn commands() { .run() .await; + TestBuilder::new() + .command(r#"TEST="1 2 " ; echo "${TEST:-}""#) + .assert_stdout("1 2 \n") + .run() + .await; + TestBuilder::new() .command(r#""echo" "1""#) .assert_stdout("1\n")