archives

« Bugzilla Issues Index

#594 — String.prototype.split with undefined separator and limit 0


The following paragraph appears in ES 6 Rev 9 section 15.5.4.14 (it is unchanged from ES 5.1):

“If separator is undefined, then the result array contains just one String, which is the this value (converted to a String). If limit is not undefined, then the output array is truncated so that it contains no more than limit elements.”

This is ambiguous about whether the limit argument applies when separator is undefined. The algorithm steps that follow, by my reading, specify that limit should not affect the result if separator is undefined. In other words, 'undefined'.split(undefined, 0) should return ['undefined'], not [].

Was this special case for the limit argument intentional? Although this is a minor issue, the special case seems unnecessary and wrong.

Browser test results:

Chrome 20, Chrome Canary 22:
'undefined'.split(); // –> ['undefined']
'undefined'.split(undefined); // –> ['undefined']
'undefined'.split(undefined, 0); // –> ['undefined']

IE 9 (IE 9 standards mode):
'undefined'.split(); // –> ['undefined']
'undefined'.split(undefined); // –> ['', '']
'undefined'.split(undefined, 0); // –> []

Firefox 14.0.1, Opera 12, and Safari 5.1.7:
'undefined'.split(); // –> ['undefined']
'undefined'.split(undefined); // –> ['undefined']
'undefined'.split(undefined, 0); // –> []

Safari 5.1.2:
'undefined'.split(); // –> Didn't test
'undefined'.split(undefined); // –> ['', '']
'undefined'.split(undefined, 0); // –> []


FWIW, here are the results for Safari 6.0 (8536.25) which shipped with OS X 10.8 Mountain Lion:

'undefined'.split(); // ['undefined']
'undefined'.split(undefined); // ['undefined']
'undefined'.split(undefined, 0); // []


fixed in rev 20 editor's draft

Note that the algorithms in ES3, 5, and 6 all return an empty array when the limit parameter is 0.

Moved all of the prose functionality description to the end as an informative note. Only the algorithm is normative.


fixed in rev20 draft, Oct. 28, 2013