Skip to content

Commit 03f0ad5

Browse files
author
Radu Samson
committed
deps: V8: cherry-pick 1e7ee91de775
Original commit message: [regexp] Reset flags between negative lookaround branches e540e1161b0 (bug 510487690) reset the analysis-time flags between the alternatives of a ChoiceNode, since an alternative's sub-graph may contain a MODIFY_FLAGS node. NegativeLookaroundChoiceNode has its own visitor and was left out, so a modifier group inside a negative lookaround still leaks its flags into the continuation. /(?!(?i:x|y))[K]/.exec('kz') // "k", should be null The lookaround body is visited first and leaves the group's flags behind; the continuation's class ranges are then made case independent under those flags rather than the pattern's, so [K] picks up 'k'. Only class ranges are affected: TextNode::MakeCaseIndependent materializes the equivalents during analysis, while atoms get their case closure at emission time from the restored flags. A single- alternative body does not reproduce either, since its restore node is emitted last. Change-Id: I4077076b9dbee6acf75918a2c4f7bf7d86cab059 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8175612 Auto-Submit: Jakob Linke <[email protected]> Reviewed-by: Patrick Thier <[email protected]> Commit-Queue: Patrick Thier <[email protected]> Cr-Commit-Position: refs/heads/main@{#109043} Adjusted for the V8 version in deps: use RegExpFlags instead of the Flags alias, which does not exist there. Refs: v8/v8@1e7ee91 Refs: nodejs#66277 Assisted-by: Claude Code Signed-off-by: Radu Samson <[email protected]>
1 parent 380afb0 commit 03f0ad5

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎common.gypi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
# Reset this number to 0 on major V8 upgrades.
4646
# Increment by one for each non-official patch applied to deps/v8.
47-
'v8_embedder_string': '-node.44',
47+
'v8_embedder_string': '-node.45',
4848

4949
##### V8 defaults for Node.js #####
5050

‎deps/v8/src/regexp/regexp-compiler.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3889,11 +3889,13 @@ class Analysis : public NodeVisitor {
38893889
NegativeLookaroundChoiceNode* that) override {
38903890
DCHECK_EQ(that->alternatives()->length(), 2); // Lookaround and continue.
38913891

3892+
RegExpFlags header_flags = flags();
38923893
EnsureAnalyzed(that->lookaround_node());
38933894
if (has_failed()) return;
38943895
STATIC_FOR_EACH(
38953896
Propagators::VisitNegativeLookaroundChoiceLookaroundNode(that));
38963897

3898+
set_flags(header_flags);
38973899
EnsureAnalyzed(that->continue_node());
38983900
if (has_failed()) return;
38993901
STATIC_FOR_EACH(

‎deps/v8/test/mjsunit/regexp-modifiers.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@ test(/(?i:\.|\bnuLl)/, ['null', 'NULL']);
102102
test(/(?i:\.|\bnulL)/, ['null', 'NULL']);
103103
test(/(?-i:(?i:\.|\bNULL))/, ['null', 'NULL', '.foo'], ['xyz']);
104104
test(/(?i:(?-i:\.|\bNULL))/, ['NULL', '.foo'], ['null', 'xyz']);
105+
106+
// A modifier group inside a negative lookaround must not leak its flags into
107+
// the continuation. Analysis visits the two branches of the lookaround choice
108+
// in sequence, so without a reset the continuation's classes are made case
109+
// independent under the group's flags rather than the pattern's.
110+
test(/(?!(?i:x|y))[K]/, ['K'], ['k']);
111+
test(/(?<!(?i:x|y))[K]/, ['K'], ['k']);
112+
test(/(?!(?-i:x|y))[K]/i, ['K', 'k']);

0 commit comments

Comments
 (0)