Module: wine Branch: master Commit: 1045bffcc018dba1ee26a34620f6732eb0c3a795 URL: http://source.winehq.org/git/wine.git/?a=commit;h=1045bffcc018dba1ee26a34620...
Author: Jacek Caban jacek@codeweavers.com Date: Tue Dec 8 01:13:27 2009 +0100
jscript: Fixed String.split for missing regexp separator.
---
dlls/jscript/string.c | 8 +++++--- dlls/jscript/tests/regexp.js | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index 97c807f..95ad773 100644 --- a/dlls/jscript/string.c +++ b/dlls/jscript/string.c @@ -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) { diff --git a/dlls/jscript/tests/regexp.js b/dlls/jscript/tests/regexp.js index c9066c6..ff00285 100644 --- a/dlls/jscript/tests/regexp.js +++ b/dlls/jscript/tests/regexp.js @@ -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);