New issue
Advanced search Search tips
Starred by 33 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
HW: ----
NextAction: ----
OS: ----
Priority: 2
Type: Bug
ES5



Sign in to add a comment

RegExp.source should return a valid pattern

Project Member Reported by adamk@chromium.org, Mar 1 2012

Issue description

(new RegExp()).source now returns '(:?)' in JSC, whereas it returns '' in V8.

JSC just changed their behavior, see https://bugs.webkit.org/show_bug.cgi?id=79938 for their reasoning (the short answer is that it matches the pattern generated by toString()).

For now I'm suppressing this failure in V8 WebKit layout tests. If you disagree with the reasoning in the WebKit bug, please ping back so we can fix the WebKit test.
 
 Issue 1983  has been merged into this issue.
Cc: rossberg@chromium.org
Labels: Type-Bug Priority-Medium ES5
Owner: mstarzinger@chromium.org
Status: Assigned
new RegExp("/").toString() also has different behaviour between V8 and JSC.  JSC will return "/\//" where V8 returns "///".

The standard says that RegExp.prototype.toString must return '/' + source + '/', and also states that the result must be a valid RegularExpressionLiteral.  These two requirements are clearly contradictory, and JSC seems to be standardizing on the second of the two.
Here's another one:  var re = new RegExp("\n").  Both JSC and V8 will return a string with a literal newline in it, which 'eval' cannot understand.
Erik, toString should use the 'source' property of the regexp object, which Section 15.10.4.1 specifies to be the properly escaped version of the original string. The same paragraph also specifies explicitly that 'source' should be set to "(?:)" if the original string is empty.

So no contradiction, we are just wrong.

This is related to  issue 956 .
Cc: erik.co...@gmail.com lrn@chromium.org mstarzinger@chromium.org lrn@chromium.org
 Issue 956  has been merged into this issue.
Summary: RegExp.source should return a valid pattern
Fixed (for empty RegExp) in r11416. More general escaping still missing, leaving issue open.

Comment 10 by ing...@gmail.com, Jun 29 2015

Another failing case - This is a bug for `new RegExp("\n").toString()` as pointed out in https://github.com/benjamingr/RegExp.escape/issues/30 
Labels: Priority-2

Comment 12 Deleted

Cc: jgruber@chromium.org
 Issue 6850  has been merged into this issue.
Cc: -lrn@chromium.org -erik.co...@gmail.com -rossberg@chromium.org -mstarzinger@chromium.org
Components: Regexp
Owner: ----
Status: Available (was: Assigned)
Cc: littledan@chromium.org yangguo@chromium.org
 Issue 5329  has been merged into this issue.

Sign in to add a comment