tc39 / proposal-regex-escaping

Proposal for investigating RegExp escaping for the ECMAScript standard
http://tc39.es/proposal-regex-escaping/
Creative Commons Zero v1.0 Universal
363 stars 32 forks source link

updates to EscapedChars.md #34

Closed bergus closed 9 years ago

bergus commented 9 years ago

as suggested in #31

bergus commented 9 years ago

Uh, wait, is the following behaviour (tested in my browser console) actually buggy?

>>> new RegExp("\\u41" + "B").test("u41B")
false
>>> new RegExp("\\u41" + "B").test("\u041B")
true

If I append a non-hexadecimal character, it matches the literal letters (and treats \u as an IdentityEscape):

>>> new RegExp("\\u41" + "B%").test("u41B%")
true
>>> new RegExp("\\u41" + "B%").test("\u041B%")
false
domenic commented 9 years ago

Chrome has some bugs in this area, so definitely test a few browsers.

bergus commented 9 years ago

The test above was in (old) Opera. But before testing browsers, I wanted to get a confirmation that I've correctly understood the spec and the first snippet demonstrates a bug?

anba commented 9 years ago

But before testing browsers, I wanted to get a confirmation that I've correctly understood the spec and the first snippet demonstrates a bug?

The first snippet should give the following output (*):

js> new RegExp("\\u41" + "B").test("u41B")
true
js> new RegExp("\\u41" + "B").test("\u041B")
false

For Unicode enabled RegExps (or implementations without support for extension "B.1.4 Regular Expressions Patterns"), new RegExp("\\u41" + "B") throws a SyntaxError.

(*): Also tested in Edge, V8, JavaScriptCore, Nashorn and SpiderMonkey

benjamingr commented 9 years ago

Thanks @bergus !