Closed bergus closed 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
Chrome has some bugs in this area, so definitely test a few browsers.
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?
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
Thanks @bergus !
as suggested in #31