Skip to content

Commit

Permalink
[regexp] Fix matching of regexps that are both sticky and anchored at…
Browse files Browse the repository at this point in the history
… 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}
  • Loading branch information
mraleph authored and Commit bot committed Nov 17, 2016
1 parent e003a45 commit 29745ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/regexp/jsregexp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6742,8 +6742,7 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(
// Inserted here, instead of in Assembler, because it depends on information
// in the AST that isn't replicated in the Node structure.
static const int kMaxBacksearchLimit = 1024;
if (is_end_anchored &&
!is_start_anchored &&
if (is_end_anchored && !is_start_anchored && !is_sticky &&
max_length < kMaxBacksearchLimit) {
macro_assembler.SetCurrentPositionFromEnd(max_length);
}
Expand Down
7 changes: 7 additions & 0 deletions test/mjsunit/es6/regexp-sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,10 @@ mhat.lastIndex = 2;
assertFalse(mhat.test("..foo"));
mhat.lastIndex = 2;
assertTrue(mhat.test(".\nfoo"));

// Check that we don't apply incorrect optimization to sticky regexps that
// are anchored at end.
var stickyanchored = /bar$/y;
assertFalse(stickyanchored.test("foobar"));
stickyanchored.lastIndex = 3;
assertTrue(stickyanchored.test("foobar"));

0 comments on commit 29745ee

Please sign in to comment.