Bug 68348 - String#split is buggy
Summary: String#split is buggy
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL: http://stevenlevithan.com/demo/split.cfm
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-19 04:19 PDT by Mathias Bynens
Modified: 2011-09-19 18:41 PDT (History)
7 users (show)

See Also:


Attachments
Fix (25.20 KB, patch)
2011-09-19 18:03 PDT, Gavin Barraclough
sam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mathias Bynens 2011-09-19 04:19:25 PDT
Spec: http://es5.github.com/x15.5.html#x15.5.4.14
Test case: http://stevenlevithan.com/demo/split.cfm

'.'.split(/()()/); // should return ["."] but instead returns ["", "", "."]
'.'.split(/(.??)(.??)/); // should return ["."] but instead returns ["", "", "."]
'tesst'.split(/(s)*/); // should return ["t", undefined, "e", "s", "t"] but returns [undefined, "t", undefined, "e", "s", undefined, "t"]
'tesst'.split(/(s)*?/); // should return ["t", undefined, "e", undefined, "s", undefined, "s", undefined, "t"] but returns [undefined, "t", undefined, "e", undefined, "s", undefined, "s", undefined, "t"]
'tesst'.split(/(s*)/); // should return ["t", "", "e", "ss", "t"] but returns ["", "t", "", "e", "ss", "", "t"]
'tesst'.split(/(s*?)/); // should return ["t", "", "e", "", "s", "", "s", "", "t"] but returns ["", "t", "", "e", "", "s", "", "s", "", "t"]
Comment 1 Gavin Barraclough 2011-09-19 18:03:18 PDT
Created attachment 107951 [details]
Fix
Comment 2 WebKit Review Bot 2011-09-19 18:07:17 PDT
Attachment 107951 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'LayoutTests/ChangeLog', u'LayoutTests/fast..." exit_code: 1

Source/JavaScriptCore/runtime/StringPrototype.cpp:824:  Should have only a single space after a punctuation in a comment.  [whitespace/comments] [5]
Source/JavaScriptCore/runtime/StringPrototype.cpp:827:  Should have only a single space after a punctuation in a comment.  [whitespace/comments] [5]
Source/JavaScriptCore/runtime/StringPrototype.cpp:928:  Semicolon defining empty statement for this loop. Use { } instead.  [whitespace/semicolon] [5]
Total errors found: 3 in 12 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Sam Weinig 2011-09-19 18:09:04 PDT
Comment on attachment 107951 [details]
Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=107951&action=review

> Source/JavaScriptCore/runtime/StringPrototype.cpp:806
> +    // 3. Let A be a new array created as if by the expression new Array()where Array is the

Weird spacing.

> Source/JavaScriptCore/runtime/StringPrototype.cpp:813
> +    // 5. If limit is undefined, let lim = 2^32รข1; else let lim = ToUint32(limit).

I think you have a unicode!
Comment 4 Gavin Barraclough 2011-09-19 18:41:00 PDT
Fixed in r95504