Repository navigation
fix(parse): =~ regex word fragments are word data, never reserved words (fixes #461) - #473
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #461. Residue of #322.
Root cause
GNU reads the whole
=~RHS as ONE word under PST_REGEXP:read_token_wordfolds
|viagot_characterand(...)viaparse_matched_pair(parse.y:5443-5461), and
read_tokenjumps straight totokword(parse.y:3663), so reserved-word recognition never happens inside the regex.
Rubash splits that word into several tokens, and a Keyword fragment like
caseafter the regex's unquoted|sat in reserved-word position: thewhile/untilcondition boundary scanner (find_loop_do->update_compound_boundary_stack) pushed a phantomcaseframe whoseesacnever came, so
dowas never found at depth 0 and the loop parse died withsyntax error near unexpected token 'do'(breaks shellapiodsel.shellapi.bashline 59). The #322 fix covered the parenthesized formand the top-level/
ifpositions but not this one.Fix
src/lexer/scanner.rs: the lexer already models the still-open RHS word(
LexerParseState::cond_rhs_*, [bug] [[ string =~ ^(a|b)$ ]] with unquoted parenthesized regex aborts the parse: 'unexpected end of file from (' — pbb is_hex_color section dies #322/[bug] Parser rejects GNU-valid input: ((# 1 + 2)), { foo } }; }, pattern-replacement with $'\'' quote, heredoc after 'cat <<EOF ;;' in case arm, [[ a =~ ( ]]<>;&) ]] #222);record_tokennow stamps everyfragment of that word with the new
Token::regexp_rhs_fragmentflag.src/parser/support.rs: reserved-word recognition and the compound-boundarygrammar are inert for flagged tokens (
is_keywordfragment-blind, earlyreturn in
update_compound_boundary_stack) — the GNUgoto tokwordsemantics. This covers while/until conditions, function and coproc
loop-end scans, quoted and unquoted forms;
[[ ]]interiors are untouched(
merge_pattern_rhs_fragmentsstill owns the word), and real pipelinesoutside
[[ ]]are unaffected.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,-nrc=0 on allshapes 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).