Skip to content

Forbidden extension in RegExp pattern grammar #4368

@mathiasbynens

Description

@mathiasbynens

See https://tc39.github.io/ecma262/#sec-forbidden-extensions (and https://bugs.ecmascript.org/show_bug.cgi?id=3157 for more background):

The RegExp pattern grammars in 21.2.1 and B.1.4 must not be extended to recognize any of the source characters A-Z or a-z as IdentityEscape[+U] when the [U] grammar parameter is present.

Chakra incorrectly extends the grammar in this way, which is especially problematic for \p and \P:

$ eshost -e '/\p{Script_Extensions=Greek}/u.test("π")'
#### Chakra
false

#### JavaScriptCore
true

#### V8
true

This presents a compatibility risk. One might reasonably assume that if the above RegExp compiles without throwing an exception, the engine supports Unicode property escapes, and then rely on the results that it produces. With the current behavior, that would result in incorrect results.

Any of the following should throw an exception:

/\p/u;
/\P/u;
/\a/u;
/\A/u;
/\e/u;
/\E/u;
/\y/u;
/\Y/u;
/\z/u;
/\Z/u;

And this should throw an exception until Unicode property escapes are implemented:

/\p{Script_Extensions=Greek}/;
/\P{Script_Extensions=Greek}/;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions