Invalid Octal Escapes in Regular Expressions
Although not specified in ES5, octal escapes are required in regular expressions for web reality [1,2]. [1] even claims the extensions are "extensive and consistent across browsers". But for invalid octal escapes, the browsers are not consistent. For example: /^\8$/ matches "\8" in Spidermonkey, JSC and Opera, whereas in IE10 and V8, /^\8$/ matches "8". /^\777$/ matches "\x3F7" in SM, JSC, Opera and V8, whereas in IE10, /^\777$/ matches "\u01FF". Is there going to be any kind of consolidation for ES6?
Yes - the goal of [1] and [2] is to include normative optional text in Annex B of ES6 which nails down more of the behavior. The spec text in [2] was an attempt to describe the shared common ground. From your examples, it looks like there remain places where there are disagreements between browsers even in the limited extension this spec text aims to cover.
I'll put discussion of [2] on the agenda for the upcoming TC39 f2f meeting.
For reference - that candidate spec text gives the following behavior for your two examples:
/^\8$/ matches "8". It is treated as an IdentityEscape because it is not a valid DecimalEscape or OctalEscapeSequence.
/^\777$/ matches "\x3F7". It is treated as an OctalEscapeSequence followed by a 7.
Luke
Thanks for your answer, then I'm looking forward to the meeting results.
- André
PS: Here's another difference, /^\0000$/ matches "\0" in SM, JSC and Opera, whereas in IE10 and V8 it matches "\u00000" (that's "\0" concat'ed with "0"). Per [2] it ought to be "\u00000".
Although not specified in ES5, octal escapes are required in regular expressions for web reality [1,2]. [1] even claims the extensions are "extensive and consistent across browsers". But for invalid octal escapes, the browsers are not consistent. For example:
/^\8$/ matches "\8" in Spidermonkey, JSC and Opera, whereas in IE10 and V8, /^\8$/ matches "8".
/^\777$/ matches "\x3F7" in SM, JSC, Opera and V8, whereas in IE10, /^\777$/ matches "\u01FF".
Is there going to be any kind of consolidation for ES6?
Thanks, André
[1] harmony:regexp_match_web_reality [2] strawman:match_web_reality_spec