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

fix example for hexadecimal escape #35

Closed bergus closed 9 years ago

bergus commented 9 years ago

Follow up to #34. @anba I knew it, damn.

benjamingr commented 9 years ago

Thanks

domenic commented 9 years ago

This still doesn't make much sense. new RegExp("\\u004" + "A").test("u004A") === false.

mathiasbynens commented 9 years ago

I don’t understand the confusion.

RegExp('\\u004' + 'A').test('J');
// → true

RegExp('\\u004' + 'A', 'u').test('J');
// → true

This patch makes sure that:

RegExp('\\u004' + RegExp.escape('A')).test('J');
// → false

RegExp('\\u004' + RegExp.escape('A'), 'u').test('J');
// → throws
anba commented 9 years ago

If it's required (or desirable) to prevent RegExp('\\u004' + RegExp.escape('A')) expanding to RegExp('\\u004A'), then you probably also want to make sure RegExp('\\c' + RegExp.escape('G')) does not expand to RegExp('\\cG'). That means not only 0-9A-Fa-f, but actually 0-9A-Za-z_ needs to be escaped.

bergus commented 9 years ago

@anba Can you add that to #29, please? I didn't think /\c/ alone was valid, but it seems to compile indeed (though I don't see what it matches).

anba commented 9 years ago

@bergus Added a comment to the other issue.