Skip to content

Commit 7241944

Browse files
authored
Preserve space in variables (#216)
1 parent 9bb43af commit 7241944

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

crates/deno_task_shell/src/shell/execute.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use crate::shell::types::FutureExecuteResult;
3535
use crate::shell::types::ShellPipeReader;
3636
use crate::shell::types::ShellPipeWriter;
3737
use crate::shell::types::ShellState;
38+
use crate::shell::types::TextPart::Text as OtherText;
3839

3940
use crate::parser::Arithmetic;
4041
use crate::parser::ArithmeticPart;
@@ -1239,7 +1240,11 @@ impl VariableModifier {
12391240
match self {
12401241
VariableModifier::DefaultValue(default_value) => {
12411242
match state.get_var(name) {
1242-
Some(v) => Ok((v.clone().into(), None)),
1243+
Some(v) => {
1244+
let t: Text =
1245+
Text::new([OtherText(v.clone().to_string())].to_vec());
1246+
Ok((t, None))
1247+
}
12431248
None => {
12441249
let v = evaluate_word(default_value.clone(), state, stdin, stderr)
12451250
.await
@@ -1470,7 +1475,9 @@ fn evaluate_word_parts(
14701475
} else if let Some(val) =
14711476
state.get_var(&name).map(|v| v.to_string())
14721477
{
1473-
Ok(Some(val.into()))
1478+
let t: Text =
1479+
Text::new([OtherText(val.clone().to_string())].to_vec());
1480+
Ok(Some(t))
14741481
} else {
14751482
Err(miette::miette!("Undefined variable: {}", name))
14761483
}

crates/tests/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ async fn commands() {
5353

5454
TestBuilder::new()
5555
.command(r#"TEST="1 2" ; echo $TEST"#)
56-
.assert_stdout("1 2\n")
56+
.assert_stdout("1 2\n")
57+
.run()
58+
.await;
59+
60+
TestBuilder::new()
61+
.command(r#"TEST="1 2 " ; echo "${TEST:-}""#)
62+
.assert_stdout("1 2 \n")
5763
.run()
5864
.await;
5965

0 commit comments

Comments
 (0)