Is '\ 0' followed by a decimal digit in a string allowed in ECMA-262 strict mode?

According to the ECMA-262 (6th Edition) specification, in strict mode, in single or double quotes after the '\', it is possible to have an EscapeSequence or LineTerminatorSequence, and the EscapeSequence must be one of the following: CharacterEscapeSequence, 0 [lookahead โˆ‰ DecimalDigit], HexExEquenceSequence, UnicodeEscapeSequence (see 11.8.4).

Does this mean that it is completely incorrect to have any DecimalDigit after '\ 0' at all?

I understand it is done this way to avoid confusion with the LegacyOctalEscapeSequence (from B.1.2), but the first "\ 0" only required octal digits, and the V8 engine seems to support it that way (see below).

After checking with implementations, it turns out that the V8 engine allows for a "\ 0" followed only by DecimalDigit, which is not OctalDigit. In this case, it resolves it to a string with string values โ€‹โ€‹0 at the first position and then the next digit's code point value as SourceCharacter. When it is assigned OctalDigit after "\ 0", it will throw a SyntaxError with the message "Octal escape sequences are not allowed in strict mode", which is a bit misleading. Chakra and SpiderMonkey seem to throw a SyntaxError on any DecimalDigit after "\ 0", but with a similar message about octal escape sequences that look especially strange in some cases (with "8" or "9" after "\ 0",which cannot be an octal escape sequence outside of strict mode).

So my question is the correct interpretation of the spec?

+3


source to share


1 answer


"0 [lookahead โˆ‰ DecimalDigit]" sounds pretty straightforward to me: after a \0

decimal digit is not allowed.

This means that a bug in what V8 allows "\08"

and "\09"

in strict mode is a bug. Could you find the bug at https://bugs.chromium.org/p/v8/ ?



Interestingly, test262 doesn't seem to cover this case at all ...

Quite different: all browsers accept "\8"

and "\9"

in strict mode, which, according to the spec, should raise a SyntaxError. There's a thread at esdiscuss.org indicating that this is a violation of the spec (or at least sometime) it is required for web compatibility: if existing websites depend on non-spec behavior, then browsers usually can't just update its behavior to be compliant with the requirements, as it would break such sites and the correct use of the websites is more important to users (and therefore browser developers) than compatibility with the specifications.

+2


source







All Articles