Skip to content

fix: reset stateful regexps when matching request data - #3011

Merged
mikicho merged 1 commit into
nock:betafrom
jakezwang:fix-stateful-data-regex
Sep 21, 2026
Merged

mikicho merged 1 commit into
nock:betafrom
jakezwang:fix-stateful-data-regex

Conversation

@jakezwang

Copy link
Copy Markdown

Reset global and sticky regular expressions before comparing request data. A reused matcher in .query() or a nested JSON body currently retains lastIndex, so the next identical request can fail to match. This applies the existing URL-matching behavior to data comparisons while leaving ordinary, potentially frozen regexps untouched.

Adds regressions for repeated query/body requests and a shared regexp across object and array values. All six regressions fail before the fix; the frozen-regexp control passes on both versions.

Validation: npm test (662 passing, 9 existing pending), npm run test:leak, and npm run test:build on Node 22 and 24; npm run lint and npm run format.

@mikicho
mikicho merged commit 9ab7dca into nock:beta Sep 21, 2026
10 checks passed
@mikicho

mikicho commented Sep 21, 2026

Copy link
Copy Markdown
Member

Thank you!

@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 15.0.0-beta.15 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants