forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This provides implementations of our Unicode-savvy regexp instructions, which decode surrogate pairs. Reviewed By: avp Differential Revision: D17413812 fbshipit-source-id: dc983858b8ad175fff837f12eb6a082f1686dc15
- Loading branch information
1 parent
892bf2c
commit 1cbe62e
Showing
3 changed files
with
135 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. | ||
// | ||
// This source code is licensed under the MIT license found in the LICENSE | ||
// file in the root directory of this source tree. | ||
// | ||
// RUN: LC_ALL=en_US.UTF-8 %hermes -non-strict -O -target=HBC %s | %FileCheck --match-full-lines %s | ||
|
||
print('RegExp Unicode'); | ||
// CHECK: RegExp Unicode | ||
|
||
try { new RegExp("\\u{FFFFFFFFF}", "u"); } catch (e) { print(e.message); } | ||
// CHECK-NEXT: Invalid RegExp pattern: Escaped value too large | ||
|
||
print(/abc/ui.exec("AbC")); | ||
// CHECK-NEXT: AbC | ||
|
||
print(/\u{48}/.exec("H")); | ||
// CHECK-NEXT: null | ||
|
||
print(/\u{48}/u.exec("H")); | ||
// CHECK-NEXT: H | ||
|
||
print(/\110/.exec("H")); | ||
// CHECK-NEXT: H | ||
|
||
try { new RegExp("\\110", "u"); } catch (e) { print(e.message); } | ||
// CHECK-NEXT: Invalid RegExp pattern: Invalid escape | ||
|
||
try { new RegExp("\\u{}", "u"); } catch (e) { print(e.message); } | ||
// CHECK-NEXT: Invalid RegExp pattern: Invalid escape | ||
|
||
try { new RegExp("\\u{ABC", "u"); } catch (e) { print(e.message); } | ||
// CHECK-NEXT: Invalid RegExp pattern: Invalid escape | ||
|
||
try { new RegExp("\\u{}", "u"); } catch (e) { print(e.message); } | ||
// CHECK-NEXT: Invalid RegExp pattern: Invalid escape | ||
|
||
try { new RegExp("\\u}", "u"); } catch (e) { print(e.message); } | ||
// CHECK-NEXT: Invalid RegExp pattern: Invalid escape | ||
|
||
try { new RegExp("\\u", "u"); } catch (e) { print(e.message); } | ||
// CHECK-NEXT: Invalid RegExp pattern: Invalid escape | ||
|
||
try { new RegExp("\\uZZZZ", "u"); } catch (e) { print(e.message); } | ||
// CHECK-NEXT: Invalid RegExp pattern: Invalid escape | ||
|
||
try { new RegExp("\\u{FFFFFFFFF}", "u"); } catch (e) { print(e.message); } | ||
// CHECK-NEXT: Invalid RegExp pattern: Escaped value too large | ||
|
||
print(/\u{1F600}/.exec("\u{1F600}")); | ||
// CHECK-NEXT: null | ||
|
||
// Here the match has length 2, because this emoji must be encoded via | ||
// a surrogate pair. | ||
print(/\u{1F600}/u.exec("\u{1F600}")[0].length); | ||
// CHECK-NEXT: 2 | ||
|
||
// Here we expect to match because the surrogate pair looks like two characters to a non-unicode regexp. | ||
print(!! /^..$/.exec("\u{1F600}")); | ||
// CHECK-NEXT: true | ||
|
||
// Here we expect to not match because the surrogate pair should look like one character to a non-unicode regexp. | ||
print(!! /^..$/u.exec("\u{1F600}")); | ||
// CHECK-NEXT: false | ||
print(!! /^.$/u.exec("\u{1F600}")); | ||
// CHECK-NEXT: true |