Skip to content

Commit

Permalink
Avoid matching Newline in U16MatchAnyButNewline.
Browse files Browse the repository at this point in the history
Summary:
The `U16MatchAnyButNewline` instruction is supposed to perform
the same `isLineTerminator` check that `MatchAnyButNewline` performs,
but it didn't.

Add the check and add a test.

Reviewed By: dulinriley

Differential Revision: D19146240

fbshipit-source-id: f3bae36ffec8398ba185992bc43f85b82bb37586
  • Loading branch information
avp authored and facebook-github-bot committed Jan 6, 2020
1 parent a174d21 commit faf10b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/Regex/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,8 @@ auto Context<Traits>::match(State<Traits> *s, bool onlyAtStart)
break;

case Opcode::U16MatchAnyButNewline:
if (c.atEnd())
if (c.atEnd() || isLineTerminator(c.consumeUTF16()))
BACKTRACK();
c.consumeUTF16();
s->ip_ += sizeof(U16MatchAnyButNewlineInsn);
break;

Expand Down
6 changes: 6 additions & 0 deletions test/hermes/regexp_unicode.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ print(!! /^..$/u.exec("\u{1F600}"));
print(!! /^.$/u.exec("\u{1F600}"));
// CHECK-NEXT: true

// Ensure that we don't match newlines with the dot.
print(/.*/u.exec("abc\ndef"), "DONE");
// CHECK-NEXT: abc DONE
print(/.*/u.exec("\u0101bc\ndef")[0].length);
// CHECK-NEXT: 3

// Test advanceStringIndex.
// We should not match a low surrogate in a Unicode regexp.
print(!! /\uDE42/u.exec("\uD83D\uDE42ZZZ"));
Expand Down

0 comments on commit faf10b1

Please sign in to comment.