Skip to content

Commit 1638f9a

Browse files
committed
fix(interpreter): get_ifs_separator respects local IFS
get_ifs_separator() only checked self.variables for IFS, missing local IFS declarations stored in call_stack.locals. This caused local IFS=":" to have no effect on "${arr[*]}" array joining. Fix: use expand_variable("IFS") which checks locals first.
1 parent b2132b8 commit 1638f9a

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

crates/bashkit/src/interpreter/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7977,13 +7977,16 @@ impl Interpreter {
79777977

79787978
/// Get the separator for `[*]` array joins: first char of IFS, or space if IFS unset.
79797979
fn get_ifs_separator(&self) -> String {
7980-
match self.variables.get("IFS") {
7981-
Some(ifs) => ifs
7982-
.chars()
7980+
let ifs = self.expand_variable("IFS");
7981+
if ifs.is_empty() && !self.is_variable_set("IFS") {
7982+
// IFS unset: default separator is space
7983+
" ".to_string()
7984+
} else {
7985+
// IFS set (possibly empty): first char or empty
7986+
ifs.chars()
79837987
.next()
79847988
.map(|c| c.to_string())
7985-
.unwrap_or_default(),
7986-
None => " ".to_string(),
7989+
.unwrap_or_default()
79877990
}
79887991
}
79897992

crates/bashkit/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,26 @@ mod tests {
24692469
assert_eq!(result.stdout, "a b c\n");
24702470
}
24712471

2472+
#[tokio::test]
2473+
async fn test_local_ifs_array_join() {
2474+
// Regression: local IFS=":" must affect "${arr[*]}" joining
2475+
let mut bash = Bash::new();
2476+
let result = bash
2477+
.exec(
2478+
r#"
2479+
fn() {
2480+
local arr=(a b c)
2481+
local IFS=":"
2482+
echo "${arr[*]}"
2483+
}
2484+
fn
2485+
"#,
2486+
)
2487+
.await
2488+
.unwrap();
2489+
assert_eq!(result.stdout, "a:b:c\n");
2490+
}
2491+
24722492
#[tokio::test]
24732493
async fn test_glob_star() {
24742494
let mut bash = Bash::new();

0 commit comments

Comments
 (0)