Skip to content

Commit 29745ee

Browse files
mralephCommit bot
authored andcommitted
[regexp] Fix matching of regexps that are both sticky and anchored at end.
V8 was applying incorrect optimization to them advancing the start position. This would cause /foo$/y too match "barfoo", which it should not. BUG= Review-Url: https://codereview.chromium.org/2510743003 Cr-Commit-Position: refs/heads/master@{#41077}
1 parent e003a45 commit 29745ee

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/regexp/jsregexp.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6742,8 +6742,7 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(
67426742
// Inserted here, instead of in Assembler, because it depends on information
67436743
// in the AST that isn't replicated in the Node structure.
67446744
static const int kMaxBacksearchLimit = 1024;
6745-
if (is_end_anchored &&
6746-
!is_start_anchored &&
6745+
if (is_end_anchored && !is_start_anchored && !is_sticky &&
67476746
max_length < kMaxBacksearchLimit) {
67486747
macro_assembler.SetCurrentPositionFromEnd(max_length);
67496748
}

test/mjsunit/es6/regexp-sticky.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,10 @@ mhat.lastIndex = 2;
128128
assertFalse(mhat.test("..foo"));
129129
mhat.lastIndex = 2;
130130
assertTrue(mhat.test(".\nfoo"));
131+
132+
// Check that we don't apply incorrect optimization to sticky regexps that
133+
// are anchored at end.
134+
var stickyanchored = /bar$/y;
135+
assertFalse(stickyanchored.test("foobar"));
136+
stickyanchored.lastIndex = 3;
137+
assertTrue(stickyanchored.test("foobar"));

0 commit comments

Comments
 (0)