Bug 138129

Summary: String.prototype.split gives incorrect result in some cases: "a".split(/$/) == ["a",""] not ["a"].
Product: WebKit Reporter: Lasse Reichstein Holst Nielsen <lrn>
Component: JavaScriptCoreAssignee: Matthew Mirman <mmirman>
Status: RESOLVED FIXED    
Severity: Normal CC: fpizlo, ggaren, mmirman, msaboff, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Updated split such that it does not include the empty end of line string. mmirman: review+

Description Lasse Reichstein Holst Nielsen 2014-10-28 02:44:21 PDT
String.prototype.split gives an incorrect result in some cases.
When doing "a".split(/$/), the result is ["a", ""]. The result should be ["a"].
This was seen in Safari 7.1.

From the es5 spec:
"The value of separator may be an empty String, an empty regular expression, or a regular expression that can match an empty String. In this case, separator does not match the empty substring at the beginning or end of the input String, nor does it match the empty substring at the end of the previous separator match."
In this case, the regexp can only match an empty substring at the end of the input, and by the above text, that match is ignored wrt. splitting, so the result should be the same as with no match, ["a"].
Comment 1 Radar WebKit Bug Importer 2014-10-28 23:04:43 PDT
<rdar://problem/18807403>
Comment 2 Matthew Mirman 2015-01-21 14:27:32 PST
Created attachment 245088 [details]
Updated split such that it does not include the empty end of line string.
Comment 3 Matthew Mirman 2015-01-21 14:43:52 PST
Patch landed:  http://trac.webkit.org/changeset/178860
Closing bug.