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

Discussion in 'Javascript' started by Bart Lateur, Sep 2, 2007.

  1. Bart Lateur

    Bart Lateur Guest

    In this code:

    function see(wot) {
    var a = "0: " + arguments[0];
    for (var i = 1; i < arguments.length; i++)
    a += "\n" + i + ": " + arguments;
    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.
    Bart Lateur, Sep 2, 2007
    #1
    1. Advertising

  2. Bart Lateur

    Ed Guest

    Ed, Sep 3, 2007
    #2
    1. Advertising

  3. Bart Lateur

    Bart Lateur Guest

    Ed wrote:

    >I think that's been reported:


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

    --
    Bart.
    Bart Lateur, Sep 3, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephen Ferg

    How to avoid "f.close" (no parens) bug?

    Stephen Ferg, Feb 11, 2004, in forum: Python
    Replies:
    12
    Views:
    483
    Nick Craig-Wood
    Feb 13, 2004
  2. Batista, Facundo

    RE: How to avoid "f.close" (no parens) bug?

    Batista, Facundo, Feb 11, 2004, in forum: Python
    Replies:
    2
    Views:
    240
    Neil Hodgson
    Feb 11, 2004
  3. Batista, Facundo

    RE: How to avoid "f.close" (no parens) bug?

    Batista, Facundo, Feb 11, 2004, in forum: Python
    Replies:
    2
    Views:
    272
    Peter Hansen
    Feb 11, 2004
  4. Michael Chermside

    How to avoid "f.close" (no parens) bug?

    Michael Chermside, Feb 13, 2004, in forum: Python
    Replies:
    0
    Views:
    250
    Michael Chermside
    Feb 13, 2004
  5. Peter Michaux

    requiring balanced parens in a regexp?

    Peter Michaux, Nov 10, 2006, in forum: Javascript
    Replies:
    3
    Views:
    76
    Dr J R Stockton
    Nov 10, 2006
Loading...

Share This Page