Invalid Octal Escapes in Regular Expressions

Luke Hoban lukeh at microsoft.com
Thu Mar 15 18:05:43 PDT 2012


>> 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


>> [1] http://wiki.ecmascript.org/doku.php?id=harmony:regexp_match_web_reality
>> [2] http://wiki.ecmascript.org/doku.php?id=strawman:match_web_reality_spec



More information about the es-discuss mailing list