From 748cfdc9f5b57681eef2a6d8d59c4ababd34573c Mon Sep 17 00:00:00 2001 From: Jakob Linke Date: Mon, 3 Aug 2026 12:23:20 +0200 Subject: [PATCH] deps: V8: backport 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 Reviewed-by: Patrick Thier Commit-Queue: Patrick Thier Cr-Commit-Position: refs/heads/main@{#109043} Refs: https://github.com/v8/v8/commit/1e7ee91de77500f9905ebbc5bed33c2186b1e871 Co-authored-by: Radu Samson Refs: https://github.com/nodejs/node/issues/66277 PR-URL: https://github.com/nodejs/node/pull/67207 Reviewed-by: Antoine du Hamel --- common.gypi | 2 +- deps/v8/src/regexp/regexp-compiler.cc | 2 ++ deps/v8/test/mjsunit/regexp-modifiers.js | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/common.gypi b/common.gypi index 214edd31cd8..03ed837f607 100644 --- a/common.gypi +++ b/common.gypi @@ -44,7 +44,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.47', + 'v8_embedder_string': '-node.48', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/regexp/regexp-compiler.cc b/deps/v8/src/regexp/regexp-compiler.cc index 397361031e5..ba1452be9fc 100644 --- a/deps/v8/src/regexp/regexp-compiler.cc +++ b/deps/v8/src/regexp/regexp-compiler.cc @@ -3889,11 +3889,13 @@ class Analysis : public NodeVisitor { NegativeLookaroundChoiceNode* that) override { DCHECK_EQ(that->alternatives()->length(), 2); // Lookaround and continue. + RegExpFlags header_flags = flags(); EnsureAnalyzed(that->lookaround_node()); if (has_failed()) return; STATIC_FOR_EACH( Propagators::VisitNegativeLookaroundChoiceLookaroundNode(that)); + set_flags(header_flags); EnsureAnalyzed(that->continue_node()); if (has_failed()) return; STATIC_FOR_EACH( diff --git a/deps/v8/test/mjsunit/regexp-modifiers.js b/deps/v8/test/mjsunit/regexp-modifiers.js index a57f266b606..91b1f2364bd 100644 --- a/deps/v8/test/mjsunit/regexp-modifiers.js +++ b/deps/v8/test/mjsunit/regexp-modifiers.js @@ -102,3 +102,11 @@ test(/(?i:\.|\bnuLl)/, ['null', 'NULL']); test(/(?i:\.|\bnulL)/, ['null', 'NULL']); test(/(?-i:(?i:\.|\bNULL))/, ['null', 'NULL', '.foo'], ['xyz']); test(/(?i:(?-i:\.|\bNULL))/, ['NULL', '.foo'], ['null', 'xyz']); + +// A modifier group inside a negative lookaround must not leak its flags into +// the continuation. Analysis visits the two branches of the lookaround choice +// in sequence, so without a reset the continuation's classes are made case +// independent under the group's flags rather than the pattern's. +test(/(?!(?i:x|y))[K]/, ['K'], ['k']); +test(/(?