Bug 16514

Summary: RegExp properties should not depend on RegExp.input
Product: WebKit Reporter: Kevin Millikin <kmillikin>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Severity: Normal CC: barraclough, dstorey
Priority: P2 Keywords: HasReduction
Version: 523.x (Safari 3)   
Hardware: All   
OS: All   
Description Flags
Test case none

Description Kevin Millikin 2007-12-19 04:26:10 PST
Changing RegExp.input should not change RegExp.lastMatch, RegExp.$1, etc.  In Safari 523.13:

'This seems like the right behavior'.match(/right/);
RegExp.lastMatch; // == 'right'
RegExp.input = 'Whereas this one is wrong, yo';
RegExp.lastMatch; // == 'wrong'
Comment 1 David Kilzer (:ddkilzer) 2007-12-19 05:49:21 PST
Created attachment 17989 [details]
Test case

MSIE 7 and Firefox report "right" in both cases (as expected).

Opera 9.24 reports "undefined" in both cases (apparently doesn't support these properties on their RegExp object).

A local debug build of WebKit r28828 with Safari 3.0.4 (523.12) on Mac OS X 10.4.11 (8S165) reports "right" and "wrong".
Comment 2 David Kilzer (:ddkilzer) 2007-12-19 05:51:51 PST
Not a regression from Safari 2.0.4 as it reports "undefined" for both values.

Comment 3 Kevin Millikin 2007-12-19 06:09:42 PST
Thanks for looking into this.

It looks like all the deprecated properties of the RegExp constructor (lastMatch, leftContext, rightContext, lastParen, and $1 through $9) are computed lazily based on RegExp.input.  However, RegExp.input is not necessarily the last matching subject string.
Comment 4 Gavin Barraclough 2011-09-06 22:30:36 PDT
Looks like this is a very old bug; this works fine in ToT.