Permalink
Browse files

[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}
  • Loading branch information...
mraleph authored and Commit bot committed Nov 17, 2016
1 parent e003a45 commit 29745ee927bf1f4cb3e0b0075d0a149575000f18
Showing with 8 additions and 2 deletions.
  1. +1 −2 src/regexp/jsregexp.cc
  2. +7 −0 test/mjsunit/es6/regexp-sticky.js
View
@@ -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);
}
@@ -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.