Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 1c9b16dd56d5e2d6865ef612bf2323cb0c9c9920
https://github.com/WebKit/WebKit/commit/1c9b16dd56d5e2d6865ef612bf2323cb0c9c9920
Author: Shu-yu Guo <[email protected]>
Date: 2026-08-28 (Fri, 28 Aug 2026)
Changed paths:
A JSTests/stress/regexp-dot-star-enclosure-dot-all-last-index.js
M Source/JavaScriptCore/yarr/YarrInterpreter.cpp
M Source/JavaScriptCore/yarr/YarrJIT.cpp
M Source/JavaScriptCore/yarr/YarrPattern.cpp
Log Message:
-----------
[YARR] Fix lastIndex and ^ handling in dotAll mode
https://bugs.webkit.org/show_bug.cgi?id=322037
rdar://185814135
Reviewed by Yusuke Suzuki.
This PR fixes two bugs with dotAll mode (/s).
One, lastIndex wasn't being respected in the JIT and was always considered
zero.
Two, ^.* was incorrectly handled in dotAll mode when the pattern was also in
multiline mode (/m). In that case, we still optimized ^.*<expression> to
a
DotStarEnclosure, which would produce wrong results in multiline as ^ needs to
check every line. DotStarEnclosure matches <expression> and tries to walk
backwards and "expand" the .*. This optimization is wrong for the following
example:
const re = /^.*X.*/gms;
re.lastIndex = 1;
re.exec("aXb\ncXd");
"aXb\ncXd" has \n at index 3, so under m the ^ positions are 0 and 4. The
search starts at 1, so 0 is out of reach and 4 is the only candidate. From 4,
.*X.* matches "cXd". DotAllEnclosure is wrong in this case because it can't
ever match something at position 4 by expanding leftward from the X at index 1.
Test: JSTests/stress/regexp-dot-star-enclosure-dot-all-last-index.js
* JSTests/stress/regexp-dot-star-enclosure-dot-all-last-index.js: Added.
(shouldBe):
(check):
(step):
* Source/JavaScriptCore/yarr/YarrInterpreter.cpp:
(JSC::Yarr::Interpreter::matchDotStarEnclosure):
* Source/JavaScriptCore/yarr/YarrJIT.cpp:
*
Source/JavaScriptCore/yarr/YarrPattern.cpp:
(JSC::Yarr::YarrPatternConstructor::optimizeDotStarWrappedExpressions):
Canonical link:
https://flagged.apple.com:443/proxy?t2=DS6c1Q7si0&o=aHR0cHM6Ly9jb21taXRzLndlYmtpdC5vcmcvMzIwMDg2QG1haW4=&emid=6561fbcc-2aa2-41de-b6a5-e69e67cb4fbf&c=11
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications