B
Bart Lateur
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?
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?