From e37da67f4981209a0c05e01580ead99eb999224b Mon Sep 17 00:00:00 2001 From: pthier Date: Thu, 13 Aug 2026 13:28:09 +0200 Subject: [PATCH] deps: V8: backport d315af3d83cf Original commit message: [regexp] Reset compiler flags between word boundary branches When compiling \b and \B word boundary checks in AssertionNode where the succeeding character type is unknown, two code paths (before_non_word and before_word) are generated sequentially. If the boundary assertion is placed inside a modifier group (e.g. (?i:\.|\bNULL)), emitting the first branch traverses through on_success and reaches the ActionNode that restores outer flags at group exit. This mutates flags without restoring it when returning to emit the second branch. Consequently, subsequent nodes in the second branch (before_word) were incorrectly compiled with outer flags instead of the modifier group's flags. This CL saves compiler->flags() and restores them before emitting the before_word branch in AssertionNode::EmitBoundaryCheck. TAG=agy Fixed: 544575761 Change-Id: I7f08bcb99c749d5e22636c8bd6eb44bd1d3e2e39 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8257209 Reviewed-by: Victor Gomes Commit-Queue: Patrick Thier Cr-Commit-Position: refs/heads/main@{#109236} Refs: https://github.com/v8/v8/commit/d315af3d83cfe3bc1709f5b140db393db42790b3 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 | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/common.gypi b/common.gypi index 03233fedb64..214edd31cd8 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.46', + 'v8_embedder_string': '-node.47', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/regexp/regexp-compiler.cc b/deps/v8/src/regexp/regexp-compiler.cc index 23027f93012..397361031e5 100644 --- a/deps/v8/src/regexp/regexp-compiler.cc +++ b/deps/v8/src/regexp/regexp-compiler.cc @@ -2134,6 +2134,7 @@ EmitResult AssertionNode::EmitBoundaryCheck(RegExpCompiler* compiler, } bool at_boundary = (assertion_type_ == AssertionNode::AT_BOUNDARY); if (next_is_word_character == Trace::UNKNOWN) { + const RegExpFlags flags = compiler->flags(); Label before_non_word; Label before_word; if (trace->characters_preloaded() != 1) { @@ -2148,6 +2149,7 @@ EmitResult AssertionNode::EmitBoundaryCheck(RegExpCompiler* compiler, at_boundary ? kIsNonWord : kIsWord)); assembler->GoTo(&ok); + compiler->set_flags(flags); assembler->Bind(&before_word); RETURN_IF_ERROR(BacktrackIfPrevious(compiler, trace, at_boundary ? kIsWord : kIsNonWord)); diff --git a/deps/v8/test/mjsunit/regexp-modifiers.js b/deps/v8/test/mjsunit/regexp-modifiers.js index 72bf8840871..a57f266b606 100644 --- a/deps/v8/test/mjsunit/regexp-modifiers.js +++ b/deps/v8/test/mjsunit/regexp-modifiers.js @@ -89,3 +89,16 @@ test( /^(?-i:(?:a|b)(?:c|d)(?:e|f)(?:g|h)(?:i|j)(?:k|l)(?:m|n)x)/i, ['acegikmx', 'bdfhjlnx'], ['acegikmX', 'bdfhjlnX']); + +// Boundary assertions inside modifier groups with alternations must not leak +// flags between branches during code generation. +test(/(?i:\.|\bNULL)/, ['null', 'NULL', 'Null', '.foo'], ['xyz']); +test(/(?i:\bNULL|\.)/, ['null', 'NULL', '.foo'], ['xyz']); +test(/(?i:\.|\BNULL)/, ['xnull', 'xNULL'], ['null', 'xyz']); +test(/(?i:\W|\bNULL)/, ['null', 'NULL', '!'], ['x']); +test(/(?i:!|\?|\bNULL)/, ['null', 'NULL', '!', '?'], ['x']); +test(/(?i:\.|\bnUll)/, ['null', 'NULL']); +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']);