![]() |
Is this a bug? Nonmatching capturing parens in regexp in replace with function are not undefined in Firefox
In this code:
function see(wot) { var a = "0: " + arguments[0]; for (var i = 1; i < arguments.length; i++) a += "\n" + i + ": " + arguments[i]; alert(a); return wot; } "There is food at the bar".replace(/(foo)|(bar)/g, see) In Firefox 2, you see 2 alert boxes with respective contents: 0: foo 1: foo 2: 3: 9 4: There is food at the bar 0: bar 1: 2: bar 3: 21 4: There is food at the bar The non-matching capture (arguments[2] in the first case, arguments[1] in the second) is the empty string, but defined. That makes it very hard to see if a capture did match the empty string, as opposed to *not* matching. In MSIE6 and Opera9 I see almost the same, but with an essenstial difference: 0: foo 1: foo 2: undefined 3: 9 4: There is food at the bar 0: bar 1: undefined 2: bar 3: 21 4: There is food at the bar If you turn it inside out, with /(foo)|(bar)/.exec("There is food at the bar") Then, in Firebug, you see: ["foo", "foo", undefined] which is the proper result. Safari 3 beta appears to show the same results as Firefox. What do you think... bug? I think it is... Where to report it? -- Bart. |
Re: Is this a bug? Nonmatching capturing parens in regexp in replace with function are not undefined in Firefox
On Sep 2, 4:04 pm, Bart Lateur <bart.lat...@pandora.be> wrote:
> What do you think... bug? I think it is... Where to report it? > > -- > Bart. I think that's been reported: https://bugzilla.mozilla.org/show_bug.cgi?id=389717 |
Re: Is this a bug? Nonmatching capturing parens in regexp in replace with function are not undefined in Firefox
Ed wrote:
>I think that's been reported: Thanks. It looks like it is indeed the exact same problem. -- Bart. |
| All times are GMT. The time now is 12:35 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.