Bug 44040 - Split with regex including an alternative | incorrectly returns splitting tokens
Summary: Split with regex including an alternative | incorrectly returns splitting tokens
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac (Intel) OS X 10.6
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-15 17:41 PDT by Guillaume Bodi
Modified: 2010-08-15 19:16 PDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Guillaume Bodi 2010-08-15 17:41:45 PDT
Splitting a string with a regex including a choice point (such as (a|b) ) will cause the splitting tokens to be part of the resulting array.

Test case:
var string = "'test1' and 'test2' or 'test3'";
alert(string.split(/(and|or)/));

Actual result:
["'test1 ", "and", " 'test2' ", "or", " 'test3'"]

Expected result:

["'test1 ", " 'test2' ", " 'test3'"]
Comment 1 Guillaume Bodi 2010-08-15 17:43:59 PDT
Correction to the results sample (missing single quote after test1):

Actual result:
["'test1' ", "and", " 'test2' ", "or", " 'test3'"]

Expected result:

["'test1' ", " 'test2' ", " 'test3'"]
Comment 2 Guillaume Bodi 2010-08-15 19:16:10 PDT
Correct behavior as per the ECMAScriptv5 specs section 15.5.4.14

Sorry for the noise.