Bug 138129 - String.prototype.split gives incorrect result in some cases: "a".split(/$/) == ["a",""] not ["a"].
Summary: String.prototype.split gives incorrect result in some cases: "a".split(/$/) =...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Matthew Mirman
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2014-10-28 02:44 PDT by Lasse Reichstein Holst Nielsen
Modified: 2015-01-21 14:43 PST (History)
5 users (show)

See Also:


Attachments
Updated split such that it does not include the empty end of line string. (3.63 KB, patch)
2015-01-21 14:27 PST, Matthew Mirman
mmirman: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.