Prevent NPCG handling from overwriting sticky flag RegExp setup#1520
Open
Br1an67 wants to merge 1 commit intozloirock:masterfrom
Open
Prevent NPCG handling from overwriting sticky flag RegExp setup#1520Br1an67 wants to merge 1 commit intozloirock:masterfrom
Br1an67 wants to merge 1 commit intozloirock:masterfrom
Conversation
The sticky flag implementation and NPCG (Non-Participating Capturing Group) handling were both unconditionally setting reCopy, causing the NPCG block to overwrite the sticky block's work on browsers like IE11 where both conditions are true. This broke XRegExp patterns that used \s character classes, as the NPCG overwrite corrupted the pattern structure that sticky handling had set up. Changed the NPCG block to only run when sticky handling is not active.
Contributor
Might wanna add these lines into the changelog.md file, being more specific than just "resolves the endless loop issue". |
Contributor
|
Also I think we should add some tests. |
zloirock
reviewed
Mar 9, 2026
Owner
zloirock
left a comment
There was a problem hiding this comment.
Can you cover this with tests?
Contributor
|
@Br1an67 ? Are you interested in continuing this? |
9fe0fdc to
7630659
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #810
Summary
This PR fixes a critical bug where the NPCG (Non-Participating Capturing Group) handling was unconditionally overwriting the
reCopyvariable that had been set up for sticky flag handling. This caused XRegExp patterns to break on IE11 and other browsers where bothUNSUPPORTED_YandNPCG_INCLUDEDconditions are true.Root Cause
In
packages/core-js/internals/regexp-exec.js, lines 71-93, there were two separateifblocks:reCopyfor sticky flag emulationreCopyfor NPCG handlingWhen both conditions were true (like on IE11), the NPCG block would overwrite the sticky block's work, corrupting the RegExp pattern and breaking XRegExp patterns that used
\scharacter classes.Changes
if (NPCG_INCLUDED)toelse if (NPCG_INCLUDED)Testing
The fix addresses the exact issue reported:
\scharacter classes will no longer be corruptedFiles Changed
Impact