Skip to content

WIP: fix(executor): reject non-POSIX class names in =~ (#1717) - #1761

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix8/regex-class
Oct 26, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix8/regex-class

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

WIP: #1717 — [[ =~ ]] accepts [[:word:]] / [[:ascii:]]; GNU rejects both with rc=2

Coverage

Refs #1717. Verification and merge go through the integration flow — please do not merge this draft directly.

Baseline (rebased 2026-10-26)

This branch was master 1560ea44 + locale2's three commits cherry-picked (#1622/#1621/#1658). locale2 has since merged as PR #1752 (merge de542703, 2026-10-26 15:48 CST), so the branch was rebased onto current master 159e74a7 (which contains fafdd352, the master tip named in the rebase order). Rebase was conflict-free: git skipped all three cherry-picks as previously applied (patch-identical to the merged commits), and the #1717 commit's hunks are byte-identical before/after (ce37d765 → 366b946d). The diff is now exactly the single #1717 commit.

Change (src/executor/conditional.rs only)

  • Class-name gate (posix_bracket_class_names_valid) and diagnostic derivation (regexp_error_reason): 14 names → the twelve wctype/POSIX names. GNU owner: lib/sh/shmatch.c:86 sh_regmatch → libc regcomp; word/ascii are regex-crate Perl classes, not wctype properties → REG_ECTYPE "Invalid character class name", rc=2 (glibc + bionic dual-oracle verified).
  • UTF-8 expansion (posix_class_unicode_expansion): drop the word arm so [[:word:]] reaches the gate verbatim instead of expanding pre-validation.
  • Glob side deliberately untouched: bash's pattern matcher has its own 14-name table by design (lib/glob/smatch.c:196-200 cclass_name[], CC_ASCII/CC_WORD; unknown glob classes are skipped, never errors). pattern.rs / locale.rs unchanged; the regression file pins the split as a control group.

Tests

tests/issue1717_regex_class_name_regressions.rs — invalid names (word/ascii/foo/Word, negated, via-variable) rc=2 + diagnostic under LC_ALL=C and C.UTF-8; the twelve legal classes unchanged in both modes; non-class bracket shapes ([:word:] char list) stay valid; glob control group (word/ascii match, foo no-match rc=1).

Progress

GNU hands the =~ pattern to libc regcomp (lib/sh/shmatch.c:86
sh_regmatch), whose [:name:] validation is the wctype property
table: exactly the twelve POSIX names. `word` and `ascii` are
regex-crate Perl classes, not wctype properties, so GNU (glibc and
bionic alike) fails them with REG_ECTYPE "Invalid character class
name", rc=2 — rubash accepted both and evaluated them.

- posix_bracket_class_names_valid: class list 14 -> 12 (the compile
  gate for both the byte and UTF-8 paths).
- regexp_error_reason: same list, so the diagnostic derivation
  agrees and yields the REG_ECTYPE text.
- posix_class_unicode_expansion: drop the `word` arm; under a UTF-8
  locale [:word:] previously expanded before validation and never
  reached the gate. The verbatim span now fails the gate like any
  other unknown name.

The glob matcher is a separate GNU subsystem with its own 14-name
table by design (lib/glob/smatch.c:196-200 cclass_name[] carries
CC_ASCII/CC_WORD; an unknown glob class is skipped, not an error) —
pattern.rs / locale.rs are untouched, and the regression file pins
that split as a control group.

Regression: tests/issue1717_regex_class_name_regressions.rs —
invalid names (word/ascii/foo/Word, negated, via-variable) rc=2 +
diagnostic under LC_ALL=C and C.UTF-8, the twelve legal classes
unchanged in both modes, non-class bracket shapes stay valid, glob
control group.
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.

1 participant