Skip to content

Fix duplicate named capturing groups and clean up regex test262 exclusions#2320

Merged
lahma merged 1 commit into
sebastienros:mainfrom
lahma:regex-fixes
Mar 6, 2026
Merged

Fix duplicate named capturing groups and clean up regex test262 exclusions#2320
lahma merged 1 commit into
sebastienros:mainfrom
lahma:regex-fixes

Conversation

@lahma

@lahma lahma commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fix RegExpPrototype groups object construction for duplicate named capturing groups: pre-initialize all unique group names with undefined in source order, then only update when a capture actually matches. This prevents non-participating groups from overwriting successful captures with undefined. Applies to exec, match, matchAll, replace, and indices.
  • Remove regexp-lookbehind feature exclusion — most lookbehind tests already pass, only 2 individual files excluded for .NET-specific capture semantics in lookbehind backreferences.
  • Clean up regex exclusions: use glob pattern for CharacterClassEscapes, remove duplicate entries, add proper categorization comments for each exclusion group.

Net result: +38 passing test262 tests (92,410 → 92,448), 0 failures, no Acornima changes needed.

Duplicate named groups fix

The core issue: when building the groups object for regex match results, iterating groups in order and calling CreateDataPropertyOrThrow for each caused non-participating groups (from unmatched alternatives) to overwrite successful captures with undefined.

Example: /(?<x>a)|(?<x>b)/.exec("b") — group 1 ((?<x>a)) doesn't match, group 2 ((?<x>b)) matches "b". Previously, processing group 1 first would set groups.x = undefined, then group 2 would set groups.x = "b" — but only if using CreateDataPropertyOrThrow which creates a new property each time. The fix uses a two-phase approach: first pre-initialize all unique names, then only update on successful captures.

6 tests with quantified groups ({2}) remain excluded due to .NET's System.Text.RegularExpressions retaining captures from previous iterations (JavaScript resets them).

Test plan

  • Full test262 suite: 0 failures, 92,448 passed
  • Jint.Tests: 0 failures
  • No .csproj, .slnx, or Directory.Packages.props changes — uses released Acornima 1.2.0

🤖 Generated with Claude Code

…sions (38 test262 tests)

- Fix RegExpPrototype groups object construction for duplicate named
  capturing groups: pre-initialize all unique group names with undefined
  in source order, then only update when a capture actually matches.
  This prevents non-participating groups from overwriting successful
  captures. Applies to exec, match, matchAll, replace, and indices.
- Remove regexp-lookbehind feature exclusion (most tests pass, only 2
  individual files excluded for .NET-specific capture semantics)
- Clean up regex exclusions: use glob for CharacterClassEscapes, remove
  duplicates, add proper categorization comments

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lahma
lahma enabled auto-merge (squash) March 6, 2026 20:34
@lahma lahma changed the title Fix duplicate named capturing groups and clean up regex test262 exclusions (38 tests) Fix duplicate named capturing groups and clean up regex test262 exclusions Mar 6, 2026
@lahma
lahma merged commit eca544f into sebastienros:main Mar 6, 2026
4 checks passed
@lahma
lahma deleted the regex-fixes branch March 6, 2026 20:43
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