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

UNCONFIRMED
Unassigned

Status

()

Core
JavaScript Engine
--
minor
UNCONFIRMED
8 years ago
3 years ago

People

(Reporter: Donny Viszneki, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

8 years ago
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
(Reporter)

Comment 1

8 years ago
Created attachment 434610 [details] [diff] [review]
doesn't work quite right yet

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)

Updated

3 years ago
Assignee: general → nobody
You need to log in before you can comment on or make changes to this bug.