Skip to content

fix(parse): =~ regex word fragments are word data, never reserved words (fixes #461) - #473

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/regex-word-reserved
Oct 9, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/regex-word-reserved

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #461. Residue of #322.

Root cause

GNU reads the whole =~ RHS as ONE word under PST_REGEXP: read_token_word
folds | via got_character and (...) via parse_matched_pair
(parse.y:5443-5461), and read_token jumps straight to tokword
(parse.y:3663), so reserved-word recognition never happens inside the regex.
Rubash splits that word into several tokens, and a Keyword fragment like
case after the regex's unquoted | sat in reserved-word position: the
while/until condition boundary scanner (find_loop_do ->
update_compound_boundary_stack) pushed a phantom case frame whose esac
never came, so do was never found at depth 0 and the loop parse died with
syntax error near unexpected token 'do' (breaks shellapi
odsel.shellapi.bash line 59). The #322 fix covered the parenthesized form
and the top-level/if positions but not this one.

Fix

Tests

tests/issue461_regexp_rhs_reserved_word_regressions.rs (12 black-box tests):
issue repro, shellapi odsel shape, all conditional positions (while/until/if/
top-level/case-body) over a reserved-word set (case if while until do done esac fi then), alternation semantics preserved, + metachar, quoted forms,
nested loop and function-body scans, real-pipeline control. The #322 suite
passes unchanged.

Oracle

Git for Windows GNU Bash 5.2.37 (D:\Git\usr\bin\bash.exe, -n rc=0 on all
shapes above, differential-checked 2026-10-09); the issue records WSL GNU
Bash 5.3.0 rc=0 for the same forms. Known residual (pre-existing, out of
scope): the unclosed-input diagnostic wording differs from GNU, and == RHS
( grouping is a separate error path (GNU also rejects it, rc=2 both).

@caomengxuan666
caomengxuan666 merged commit 009f1e3 into master Oct 9, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/regex-word-reserved branch October 9, 2026 15:25
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.

[parse] =~ regex word with unquoted | + reserved word (case/if) rejected in while/until condition — #322 residue (breaks shellapi odsel)

1 participant