Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Is this a bug? Nonmatching capturing parens in regexp in replace with function are not undefined in Firefox

Reply
Thread Tools

Is this a bug? Nonmatching capturing parens in regexp in replace with function are not undefined in Firefox

 
 
Bart Lateur
Guest
Posts: n/a
 
      09-02-2007
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.
 
Reply With Quote
 
 
 
 
Ed
Guest
Posts: n/a
 
      09-03-2007
On Sep 2, 4:04 pm, Bart Lateur <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Bart Lateur
Guest
Posts: n/a
 
      09-03-2007
Ed wrote:

>I think that's been reported:


Thanks. It looks like it is indeed the exact same problem.

--
Bart.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
requiring balanced parens in a regexp? Peter Michaux Javascript 3 11-10-2006 10:51 PM
mem_fun_ref: parens in reference of function tibirna@gmail.com C++ 2 02-03-2006 01:17 AM
[OT] PerlTidy option to close parens on function params *only* newsbot@cox.net Perl Misc 0 05-02-2005 08:00 PM
How to avoid "f.close" (no parens) bug? Stephen Ferg Python 12 02-13-2004 06:40 AM



Advertisments