Bug 26911
| Summary: | $0 backreference no longer working | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Johan Attali <johan.attali> |
| Component: | JavaScriptCore | Assignee: | 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
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 | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Keishi Hattori
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
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
I think Firefox nor Opera supports this. I don't think we'll want to implement new syntax which encourages incompatible JS.
Alexey Proskuryakov
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
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.