archives

« Bugzilla Issues Index

#326 — source property of RegExp


ES5.1 added the following requirement beyond ES3:


"The characters / occurring in the pattern shall be escaped in S as necessary to ensure that the String value formed by concatenating the Strings "/", S, "/", and F can be parsed (in an appropriate lexical context) as a RegularExpressionLiteral that behaves identically to the constructed regular expression. For example, if P is "/", then S could be "\/" or "\u002F", among other possibilities, but not "/", because /// followed by F would be parsed as a SingleLineComment rather than a RegularExpressionLiteral. If P is the empty String, this specification can be met by letting S be "(?:)"."

However, no browsers appear to have ever agreed with this in at least the following case:

new RegExp("").source !== ""

Changing the behavior of the case above breaks code in at least one place in prototype.js.

Since this was a new, breaking, requirement in ES5, but has not been implemented in practice, I'd like to suggest removing this requirement.


All browsers seem to implement the spec now from what I can see (RegExp("").source === '(?:)'). Huzzah!