Skip to content

fix(interpreter): isolate command substitution subshell state#917

Merged
chaliy merged 1 commit intomainfrom
fix/issue-910-cmdsub-function-leak
Mar 31, 2026
Merged

fix(interpreter): isolate command substitution subshell state#917
chaliy merged 1 commit intomainfrom
fix/issue-910-cmdsub-function-leak

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Mar 31, 2026

Summary

  • Command substitution $(...) now properly isolates all mutable shell state: functions, variables, arrays, associative arrays, aliases, and cwd
  • Previously only traps were snapshot/restored; now matches the explicit subshell (...) handler
  • Added spec tests for function, variable, and alias isolation in command substitutions

Test plan

  • cargo test --test spec_tests -- bash_spec_tests passes
  • New tests subst_function_isolation, subst_variable_isolation, subst_alias_isolation verify isolation
  • cargo clippy -- -D warnings clean
  • cargo fmt --check clean

Closes #910

Command substitution $(...) runs in a subshell per POSIX/bash spec.
Functions, variables, arrays, associative arrays, aliases, and cwd
defined inside $(...) were leaking to the parent shell. Now all
mutable state is snapshot/restored, matching the explicit subshell
handler.

Closes #910
@chaliy chaliy merged commit a570705 into main Mar 31, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-910-cmdsub-function-leak branch March 31, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(interpreter): functions defined in command substitution $(...) leak to parent shell

1 participant