archives

« Bugzilla Issues Index

#3212 — 11.8.4: Spec and implementations disagree about "\8" and "\9"


According to the ES5 and ES6 spec, "\8" is not a valid string and neither is "\9", however everywhere I try it (Firefox 32, Firefox 34, node, Chrome 37, esprima) they are treated like \ NonEscapeCharacter. This also seems to affect template strings.

Is this discrepancy between the spec and the implementations tracked? Could the spec be brought in line by changing EscapeCharacter from

EscapeCharacter ::
SingleEscapeCharacter
DecimalDigit
x
u

to

EscapeCharacter ::
SingleEscapeCharacter
OctalDigit
x
u


I suppose "\08" and "\09" also suffer from a similar problem. If we were able to fix the spec, then we could change

EscapeSequence ::
CharacterEscapeSequence
0 [lookahead ∉ DecimalDigit]
HexEscapeSequence
UnicodeEscapeSequence

to

EscapeSequence ::
CharacterEscapeSequence
0 [lookahead ∉ OctalDigit]
HexEscapeSequence
UnicodeEscapeSequence


I suppose this situation parallels the discussion for integer literals:

Bug and suggested patch: https://bugs.ecmascript.org/show_bug.cgi?id=2792#c11
Thread discussing it: https://mail.mozilla.org/pipermail/es-discuss/2014-August/thread.html#38596


(In reply to Gabe Levi from comment #2)
> I suppose this situation parallels the discussion for integer literals:
>

There is a big difference, in that implementations do not support "noctal integral sequences" (phew). The question here is merely to throw or not to throw a syntax error.

See Bug 1553 comment 2 for the behaviour of "\8" and "\08" across browsers. In particular, note the difference between sloppy and strict mode.


I've open Bug 3477 for a definite answer to the more general issue of backslash followed by one ore more digits in string and template literals.

*** This bug has been marked as a duplicate of bug 3477 ***