Skip to content

Instantly share code, notes, and snippets.

@bathos
Last active December 12, 2019 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bathos/09171830ee14d3d7a0d9393eb07f64ca to your computer and use it in GitHub Desktop.
Save bathos/09171830ee14d3d7a0d9393eb07f64ca to your computer and use it in GitHub Desktop.
escape-eight-and-nine.md

Trying to understand what accounts for "\8" and "\9" being considered valid string literals with identity escapes in Chrome and FF.

Annex B permits sloppy mode to include legacy octal escapes in strings. It achieves this by replacing the ‘normal’ (strict) EscapeSequence production with a new version accompanied by three new productions.

In the sloppy version, three of the alternatives are the same. The change is replacing this rule:

"0" [lookahead ∉ DecimalDigit]

With this one:

LegacyOctalEscapeSequence

The firsts set of LegacyOctalEscapeSequence is { "0", "1", "2", "3", "4", "5", "6", "7" }. So it doesn’t introduce anything that would accept "\8" or "\9". Identity escapes are handled through CharacterEscapeSequence > NonEscapeCharacter, which is seemingly unchanged:

SourceCharacterbut not one of EscapeCharacter or LineTerminator

where EscapeCharacter is:

SingleEscapeCharacter
DecimalDigit
"x"
"u"

In other words, DecimalDigit is explicitly ruled out here — and it takes 8 and 9 with it. Also FWIW there’s this note:

A conforming implementation, when processing strict mode code, must not extend the syntax of EscapeSequence to include LegacyOctalEscapeSequence as described in B.1.2.

At first I assumed an allowance for "\8" and "\9" must live somewhere in Annex B and that I was just missing it. Then I realized Chrome and FF consider them valid identity escapes even in strict mode. I’m unsure now if this is a spec/web divergence or what.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment