Bug 26911

Summary: $0 backreference no longer working
Product: WebKit Reporter: Johan Attali <johan.attali>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED INVALID    
Severity: Normal CC: ap, ddkilzer, keishi
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.5   

Johan Attali
Reported 2009-07-01 17:50:36 PDT
The $0 backreference in the replace function is no longer working and gives an undefined value even if the pattern matched. ex. "1T2".replace(/\w+/g, '<a href="http://$0">$0</a>'); is not working while "1T2".replace(/(\w+)/g, '<a href="http://$1">$1</a>'); is working. The object RegExp.$0 is to be set to undefined whatever the pattern matchin was.
Attachments
Keishi Hattori
Comment 1 2009-07-20 02:34:22 PDT
Is this true? ECMA 262 says that $n is the nth capture where n is a single digit 1-9. ECMAScript5 Draft says the same. The matched substring is $&.
Johan Attali
Comment 2 2009-07-20 09:39:44 PDT
I just tried $& and it is indeed working. Though you are absolutely right (the specs only specify that digits 1-9 to be used) you might want to keep $0 for backward compatibility, which is actually why I found and filed this bug. (In reply to comment #1) > Is this true? > ECMA 262 says that $n is the nth capture where n is a single digit 1-9. > ECMAScript5 Draft says the same. The matched substring is $&.
Keishi Hattori
Comment 3 2009-07-20 20:28:13 PDT
I think Firefox nor Opera supports this. I don't think we'll want to implement new syntax which encourages incompatible JS.
Alexey Proskuryakov
Comment 4 2009-07-22 10:39:44 PDT
Given the information above, this is an improvement in behavior. Are there any (many?) live sites affected by this change? Does IE support this syntax? Please feel free to re-open this bug for further consideration if so.
Johan Attali
Comment 5 2009-07-22 16:00:35 PDT
Well tested on IE 6, $0 is also not working either (while is $& is)... Now I'm wondering how $0 managed to become popular ?? (In reply to comment #4) > Given the information above, this is an improvement in behavior. > > Are there any (many?) live sites affected by this change? Does IE support this > syntax? Please feel free to re-open this bug for further consideration if so.
Note You need to log in before you can comment on or make changes to this bug.