Repository navigation
fix(pattern): empty extglob spans, [[ == ]] backslash, runtime extglob gate - #1179
Conversation
…hopt gate
rubash#1091: ${var//*(pat)/rep} skipped empty-string matches.
GNU subst.c pat_subst global loop calls match_pattern per position with
MATCH_ANY, and match_upattern tries p1 down to p itself — the empty match
at each gap counts, with pat_subst:9286-9304 copying one char past a
zero-length match. find_parameter_pattern_match only tried end > start,
so the zero-length arm of the replace loop was dead. Seed each start with
the once-computed empty verdict (position-independent: match_upattern
matches the pattern against the NUL-terminated empty suffix at p), except
at the NUL position itself (pat_subst's `for (...; *str;)` never sits on
it). `${w//*(a)/Q}` on `abac` is now `QQbQQc`.
rubash#1092: unquoted [[ == ]] RHS `a\\b` matched `ab` (and missed the
literal-backslash words). GNU execute_cmd.c COND_BINARY patmatch arm runs
subst.c:4077 cond_expand_word with special=1: no quote removal on the
pattern; the lexer-kept `\\` reaches sm_loop.c:121 as a literal
backslash. The general expansion decoded lex-level DATA_BACKSLASH to a
real `\`, which the matcher read as an escape. Guard it through
expansion with CASE_PATTERN_BACKSLASH_GUARD (proven to survive
expand_word_mut by the `case` arm path) and restore it as `\\`;
expansion-produced `\` keeps its escape meaning.
rubash#1093: runtime `shopt -s extglob` (via eval) did not enable later
`case` extglob arms in script files. GNU shell.c reads scripts
incrementally (reader_loop: parse each command only after previous ones
executed; evalstring.c parse_and_execute), and the shopt builtin flips
extended_glob via reset_parser (parse.y:3502). The whole-file run_source
fast path had already parsed everything. Scripts that may flip the gate
at runtime now take the grouped driver, which lexes each group after the
previous groups ran — the same whitelist-admission shape as
script_uses_aliases. `-c`/eval strings keep the single-parse semantics
GNU gives them (verified: GNU errors there too).
c93ee1c to
393e792
Compare
GNU-goldens failure fixed + rebased onto masterRoot cause of the goldens failure: driver routing, not glob logic. Fix: narrowed the heuristic to Rebase: the branch conflicted in Verification (local, Windows):
Branch: |
Closes #1091, #1092, #1093. (1) patsubst skipped zero-length *(...)/?(...) matches: seed with position-independent empty match (match_upattern on NUL-terminated empty suffix), NUL position excluded — 12-cell matrix byte-identical (QQbQQc etc). (2) [[ == ]] non-quoted RHS decoded lexer DATA_BACKSLASH to a real backslash the matcher read as escape: new expand_conditional_pattern_word escorts \x14 via CASE_PATTERN_BACKSLASH_GUARD and restores \ for the matcher; expansion-produced real backslashes keep escape meaning. (3) Whole-file pre-parse froze the extglob gate: script_uses_runtime_parse_gates detects shopt text and routes to the existing grouped driver (incremental gather->run->lex, matching GNU reader_loop; -c/eval/top-level unchanged). Tests: lib 697 + 3 new regression files + 14 related suites (100 items) + shopt suites green; GNU parity byte-identical. Known pre-existing (untouched, separate lane): [[ 'a*b' == a*b ]] strip_conditional_quote_markers CTLESC strip.