Commit 1045bffc authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Fixed String.split for missing regexp separator.

parent c665b86c
......@@ -1129,6 +1129,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
match_result_t *match_result = NULL;
DWORD length, match_cnt, i, match_len = 0;
const WCHAR *str, *ptr, *ptr2;
BOOL use_regexp = FALSE;
VARIANT *arg, var;
DispatchEx *array;
BSTR val_str, match_str = NULL;
......@@ -1153,6 +1154,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
regexp = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg));
if(regexp) {
if(is_class(regexp, JSCLASS_REGEXP)) {
use_regexp = TRUE;
hres = regexp_match(ctx, regexp, str, length, TRUE, &match_result, &match_cnt);
jsdisp_release(regexp);
if(FAILED(hres)) {
......@@ -1183,7 +1185,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
if(SUCCEEDED(hres)) {
ptr = str;
for(i=0;; i++) {
if(match_result) {
if(use_regexp) {
if(i == match_cnt)
break;
ptr2 = match_result[i].str;
......@@ -1209,7 +1211,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
if(FAILED(hres))
break;
if(match_result)
if(use_regexp)
ptr = match_result[i].str + match_result[i].len;
else if(match_str)
ptr = ptr2 + match_len;
......@@ -1218,7 +1220,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
}
}
if(SUCCEEDED(hres) && (match_str || match_result)) {
if(SUCCEEDED(hres) && (match_str || use_regexp)) {
DWORD len = (str+length) - ptr;
if(len || match_str) {
......
......@@ -301,6 +301,19 @@ ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
r = "1 12 \t3".split(re = /\s+/).join(";");
ok(r === "1;12;3", "r = " + r);
ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
r = "123".split(re = /\s+/).join(";");
ok(r === "123", "r = " + r);
ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
/* another standard violation */
r = "1 12 \t3".split(re = /(\s)+/g).join(";");
ok(r === "1;12;3", "r = " + r);
ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
re = /,+/;
re.lastIndex = 4;
r = "1,,2,".split(re);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment