Skip to content

fix: make regexp assertions independent of lastIndex - #1880

Open
xiehuanyi wants to merge 1 commit into
chaijs:mainfrom
xiehuanyi:fix/regexp-assertion-state-r2-20261013
Open

xiehuanyi wants to merge 1 commit into
chaijs:mainfrom
xiehuanyi:fix/regexp-assertion-state-r2-20261013

Conversation

@xiehuanyi

Copy link
Copy Markdown

Reusing a global or sticky RegExp makes .match() depend on its previous lastIndex. A valid positive assertion can fail, and a negated assertion can silently pass for the same matching input after an earlier match.

Evaluate stateful expressions from index zero and restore the caller's index before reporting the assertion result. Ordinary expressions are evaluated without mutation, including frozen regexps. Add regressions for repeated matches, existing index preservation, negated false positives, and frozen ordinary expressions.

Validation:

  • Two added regressions fail on unchanged main; the frozen-regexp control passes before and after.
  • npm run build and npm run lint pass.
  • Node suite: 515 passing. Chromium suite using the local Chrome executable: 514 passing.
  • git diff --check passes.

Discovery and implementation: automated OpenAI gpt-6.1-sol source review, xhigh reasoning.

Copilot AI balanced review requested due to automatic review settings October 13, 2026 08:38
@xiehuanyi
xiehuanyi requested a review from a team as a code owner October 13, 2026 08:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants