Skip to content

fix(parser): expand variables in [[ =~ $var ]] regex patterns#482

Merged
chaliy merged 1 commit intomainfrom
claude/fix-400-Y2nIj
Mar 2, 2026
Merged

fix(parser): expand variables in [[ =~ $var ]] regex patterns#482
chaliy merged 1 commit intomainfrom
claude/fix-400-Y2nIj

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Mar 2, 2026

Summary

  • Fixed [[ $line =~ $var ]] regex matching where $var was not expanded
  • Root cause: collect_conditional_regex_pattern() creates Word::literal bypassing variable expansion
  • Fix: when regex pattern contains $, use parse_word() for expansion; otherwise use literal collector to preserve parens/backslashes

Closes #400

Test plan

  • test_regex_match_from_variable
  • test_regex_match_literal
  • Spec test regex_match_in_conditional still passes
  • All 1509 tests pass

When regex pattern after =~ operator contains a variable reference ($),
use parse_word() for proper expansion instead of collect_conditional_regex_pattern()
which creates literal words. Literal regex patterns (without $) still use
the special collector to preserve parens, backslashes, etc.

Closes #400

https://claude.ai/code/session_01WZjYqxm5xMPAEe7FSHJkDy
@chaliy chaliy force-pushed the claude/fix-400-Y2nIj branch from 374125b to a726a3f Compare March 2, 2026 20:01
@chaliy chaliy merged commit 6e63506 into main Mar 2, 2026
17 checks passed
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.

fix(interpreter): [[ =~ $var ]] regex matching from variables broken

2 participants