Closed Bug 510265 Opened 15 years ago Closed 12 years ago

Make the source property of RegExp instances conform to the spec

Categories

(Rhino Graveyard :: Core, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: rspeyer, Unassigned)

References

Details

Attachments

(1 file, 1 obsolete file)

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b4) Gecko/20090423 Firefox/3.5b4
Build Identifier: Rhino 1.7 release 2 2009 03 22

As per 15.10.4.1, the source property has to be a value which could be prefixed and suffixed with the / char, and parsed as a RegExp literal functionally equivalent to this RegExp instance.

In practice this means escaping / chars so we don't end up with a //, which would parse as a comment, and handling the special case of an empty regexp pattern.

Reproducible: Always
I just took the naive approach of escaping all '/' characters in the regexp pattern, even though they are allowed unescaped in character classes.
Blocks: 489326
Attached patch new patchSplinter Review
This only encodes slashes on regexps created through the RegExp constructor, not regexp literals, and only if the slash isn't already preceded by a backslash. Note that we keep following spidermonkey in only using "(?:)" in the toString/toSource representation of empty regexps but not in its source property.

Also contains some cleanup of code added in recent commits.
Attachment #394318 - Attachment is obsolete: true
Committed patch to git master.

https://github.com/mozilla/rhino/commit/06e155e60d2c7db05841cc6d97736cf785e18f48

Raphael, let me know if you think that RegExp('').source == '' is a problem. It is against the spec, but at this point I'd rather keep changes small and remain compatible with Spidermonkey.
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
According to [1] no browser actually implements that requirement and a test was even removed from test262 because of that [2].

[1] https://bugs.ecmascript.org/show_bug.cgi?id=326
[2] http://hg.ecmascript.org/tests/test262/rev/d98f51f15440
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: