Closed Bug 554700 Opened 14 years ago Closed 2 years ago

regexp literals escape differently than non-literals in toSource(), toString(), and uneval()

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED

People

(Reporter: donny.viszneki, Unassigned)

Details

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100214 Ubuntu/9.10 (karmic) Firefox/3.5.8
Build Identifier: JavaScript-C 1.8.0 pre-release 1 2007-10-03 :P

Regular expressions look pretty when they are instantiating from a literal regular expression /like\s*this/ because the string that is used is taken directly from the parser and reflects actual source code. This can only become a problem when your regexp contains certain ASCII control characters.

donny@donny-desktop:~/src/hg/gpsee$ js -e 'print(RegExp("\x01"))' | hexdump -c
0000000   / 001   /  \n                                                
0000004

with simple patch:

donny@donny-desktop:~/src/hg/gpsee$ js -e 'print(RegExp("\x01"))' | hexdump -c
0000000   /   \   x   0   1   /  \n                                    
0000007


Reproducible: Always
This patch fixes the problem of producing annoying ASCII control codes, but it's a little overeager to escape:

donny@donny-desktop:~/src/hg/gpsee$ js -e 'print(RegExp("/"))'
/\\//

I didn't see any documentation for the final argument of js_QuoteString(). Maybe it's not even the right API for this, but I'm sure I'll hear from one of you fine Spidermonkey people in a bug comment :)
Assignee: general → nobody

This seems like it's not in terrible shape now.

Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: