What's the correct behavior for "\8" and "\9"
BelleveInvis wrote:
According to spec: Syntax error, because of that 8 or 9 does not belongs to /NonEscapeCharacter/. However, ALL browsers treat them as "8" and "9".
Web compatibility seems to require "noctal" escapes in string literals. No one has really investigated how much web content, but it was true in the past and engines don't like taking risk for little gain.
However, even in the newest draft, "\8" still should cause a syntax error. Should we change the production "EscapeCharacter -> DecimalDigit" into "EscapeCharacter -> OctalDigit" in order to make 8 and 9 belongs to NonEscapeCharacter?
However, even in the newest draft, "\8" still should cause a syntax error. Should we change the production "EscapeCharacter -> DecimalDigit" into "EscapeCharacter -> OctalDigit" in order to make 8 and 9 belongs to NonEscapeCharacter?
On Mar 24, 2013, at 6:32 AM, BelleveInvis wrote:
However, even in the newest draft, "\8" still should cause a syntax error. Should we change the production "EscapeCharacter ->DecimalDigit" into "EscapeCharacter -> OctalDigit" in order to make 8 and 9 belongs to NonEscapeCharacter?
Probably, but need to look carefully at any possible spec. interactions with OctalEscapeSequences defined in Annex B. (Note that in ES5 we make octal escapes illegal in strict mode code, but they are still allowed in non-strict code)
However, \8 and \9 DOES NOT belong to OctalEscapeSequences. There is NO octal number contains 8 or 9.
Subject: Re: What's the correct behavior for "\8" and "\9" From: allen at wirfs-brock.com Date: Sun, 24 Mar 2013 17:22:13 -0700 CC: brendan at mozilla.com; es-discuss at mozilla.org To: infinte.cdda at hotmail.com
On Mar 24, 2013, at 6:32 AM, BelleveInvis wrote:However, even in the newest draft, "\8" still should cause a syntax error. Should we change the production "EscapeCharacter ->DecimalDigit" into "EscapeCharacter -> OctalDigit" in order to make 8 and 9 belongs to NonEscapeCharacter?
Probably, but need to look carefully at any possible spec. interactions with OctalEscapeSequences defined in Annex B. (Note that in ES5 we make octal escapes illegal in strict mode code, but they are still allowed in non-strict code)
Right. Here's SpiderMonkey's shell:
js> "\8" "8" js> "\9" "9" js> "\08" "\x008" js> "\09" "\x009" js> "use strict"; "\8" "8" js> "use strict"; "\9" "9" js> "use strict"; "\08"
typein:7:0 SyntaxError: octal literals and octal escape sequences are deprecated: typein:7:0 "use strict"; "\08" typein:7:0 ..............^ js> "use strict"; "\09"
typein:8:0 SyntaxError: octal literals and octal escape sequences are deprecated: typein:8:0 "use strict"; "\09" typein:8:0 ..............^
But, according to spec, "\8" and "\9" SHOULD cause a syntax error. Because in string literals, EscapeSequence -> CharacterEscapeSequence
and CharacterEscapeSequence -> SingleEscapeCharacterCharacterEscapeSequence -> NonEscapeCharacter
The NonEscapeCharacter is defined as SourceCharacter minus SingleEscapeCharacter, DecimalDigit, x and u, therefore, 8 and 9 (belongs to DecimalDigit) SHOULD NOT be an element of SingleEscapeCharacter, then not a member of EscapeSequence, therefore, "\8" and "\9" SHOULD be illegal according to the spec.
According to spec: Syntax error, because of that 8 or 9 does not belongs to NonEscapeCharacter.However, ALL browsers treat them as "8" and "9".