Allow keywords as identifiers if at least one character is represented by a Unicode escape




7 years ago
5 years ago


(Reporter: mathias, Unassigned)


Firefox Tracking Flags

(Not tracked)




7 years ago

> Identifiers containing escape sequences are not equivalent to fully
> unescaped identifiers in the case that, after fully unescaping identifier,
> it is a ReservedWord. In particular it is possible to create Identifiers
> that unescape to a reserved word so long as at least one character is fully
> escaped. Subsequent use of such identifiers must also have at least one
> character escaped (otherwise the reserved word will be used instead) but it
> need not be the same character(s) as that originally used to create the
> identifier.

For example, this should alert 'PASS':

    function \u0074rue() { alert('PASS'); }

So should this:

    function \u0074rue() { alert('PASS'); }
Well, I think we should not allow this kind of functions. We already correctly treat escaped identifiers as keywords in every other case.

>var \u0074rue; /* SyntaxError */

It think that we allow them as function names is just an oversight and we should probably not allow that. I tried to reply to your question on twitter with the relevant Bug 638667, but I think I failed a bit there.

Because it looks like we haven't had any complains about this in the past, we should not allow more things now. (Contrary to the ES5 from my understanding)

Comment 2

7 years ago
My reading of ES5 (and I wrote the text) does not allow the above.  However the ES3 spec. might be interpreted as allowing it. 

I don't think anything should change until T39 decides what we really want to allow/disallow going forward.
>(Contrary to the ES5 from my understanding)
Badly worded, just to make it clear, ES5 does not allow keywords even as escaped identifiers.

>All interpretations of identifiers within this specification are based upon their actual >characters regardless of whether or not an escape sequence was used to contribute any >particular characters.
See which this bug should depend on (if only we had cross-bugzilla-instance dependencies!).



7 years ago
Duplicate of this bug: 770856

Comment 6

7 years ago
FTR, the compatibility requirements are now listed here:

Firefox is the only browser to error on “identifiers” like these. It may be correct behavior as per the ECMAScript spec (and in a perfect world, all engines would implement it like this, and no one would use identifiers like that), but it doesn’t match other implementations. I’m not sure how strong the compatibility requirements are, but it is a risk.

Please consider reverting the change in bug 770856 for compatibility/interoperability reasons.


Comment 7

7 years ago
(In reply to Mathias Bynens from comment #6)
> FTR, the compatibility requirements are now listed here:
> Firefox is the only browser to error on “identifiers” like these. 

that's not correct. At least IE8 and IE9 (and almost certainly pre-IE8, but I haven't tested) do not recognize such identifiers. 

So, this has never been a real interoperability requirement of the web. It has also been discussed on es-discuss and future versions of the ECMAScript specification are not going to make such identifiers legal.

Rather than pushing browsers to converge on something that been explicitly determined to be an undesirable and non-standard feature, we should be pushing browsers to converge on correctly implementing the standards. 

This should be resolved as invalid or wontfix

Comment 8

7 years ago
Okay, let’s try to get other browsers/engines to remove this non-standard extension as well, then. I’ve filed the following bugs:

* Opera/Carakan bug:
* Chrome/V8:
* Safari/JavaScriptCore:

Comment 9

5 years ago
What is the status of this? It is security significant for systems that filter or translate code in order to enforce restrictions.
Per Bug 694360, we treat var thi\u0073; as a syntax error.

Comment 11

5 years ago
So close this bug?
Assignee: general → nobody

Comment 12

5 years ago
Resolving WONTFIX since we don't want to implement comment 0 and are following ES6 due to bug 694360. If other engines fail to fix this I'm sure a new bug will be opened against us.
Last Resolved: 5 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.