JavaScript split() function incorrectly includes delimiters when matching on a RegExp

RESOLVED INVALID

Status

()

Core
JavaScript Engine
--
major
RESOLVED INVALID
12 years ago
12 years ago

People

(Reporter: dr.-evil, Unassigned)

Tracking

1.0 Branch
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

12 years ago
User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1

When trying to split a string into an Array using a RegExp to match delimiters, Firefox incorrectly includes the delimiters as values.

Reproducible: Always

Steps to Reproduce:
var v;
v="12:00 PM".split(/(\s|:)/g);
Actual Results:  
v="12,:,00, ,PM"

Expected Results:  
v="12,00,PM";

Both Internet Explorer 6 and Safari 2.0.3 handle this code correctly.  Tested with FF 1.5.0.1 on XP SP2 and OSX 10.4.5.
(Reporter)

Updated

12 years ago
Component: General → JavaScript Engine
Product: Firefox → Core
Version: unspecified → 1.0 Branch
That is as it should be. From the spec:

If separator is a regular expression that contains capturing parentheses, then each time separator is matched the
results (including any undefined results) of the capturing parentheses are spliced into the output array. (For
example, "A<B>bold</B>and<CODE>coded</CODE>".split(/<(\/)?([^<>]+)>/) evaluates to the array
["A", undefined, "B", "bold", "/", "B", "and", undefined, "CODE", "coded", "/",
"CODE", ""].)
Status: UNCONFIRMED → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → INVALID
(Reporter)

Comment 2

12 years ago
My mistake.  The RegExp I really need is /[\s:]/g.

Since both IE and Safari produced the results I wanted, I assumed FF had the bug.  Will submit this bug to MS & Apple.
You need to log in before you can comment on or make changes to this bug.