jscript: Don't skip empty strings in String.prototype.split in ES5 mode.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
b48cc9614e
commit
88d2576ae7
|
@ -1236,7 +1236,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
|
|||
ptr2 = ptr+1;
|
||||
}
|
||||
|
||||
if(!regexp || ptr2 > ptr) {
|
||||
if(!regexp || ptr2 > ptr || ctx->version >= SCRIPTLANGUAGEVERSION_ES5) {
|
||||
tmp_str = jsstr_alloc_len(ptr, ptr2-ptr);
|
||||
if(!tmp_str) {
|
||||
hres = E_OUTOFMEMORY;
|
||||
|
@ -1261,7 +1261,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
|
|||
if(SUCCEEDED(hres) && (match_str || regexp) && i<limit) {
|
||||
DWORD len = (str+length) - ptr;
|
||||
|
||||
if(len || match_str || !length) {
|
||||
if(len || match_str || !length || ctx->version >= SCRIPTLANGUAGEVERSION_ES5) {
|
||||
tmp_str = jsstr_alloc_len(ptr, len);
|
||||
|
||||
if(tmp_str) {
|
||||
|
|
|
@ -615,6 +615,41 @@ function test_string_split() {
|
|||
return;
|
||||
}
|
||||
|
||||
function test(string, separator, result) {
|
||||
var r = string.split(separator);
|
||||
ok(r == result, "\"" + string + "\".split(" + separator + ") returned " + r + " expected " + result);
|
||||
}
|
||||
|
||||
test("test", /^|\s+/, "test");
|
||||
test("test", /$|\s+/, "test");
|
||||
test("test", /^|./, "t,,,");
|
||||
test("test", /.*/, ",");
|
||||
test("test", /x*/, "t,e,s,t");
|
||||
test("test", /$|x*/, "t,e,s,t");
|
||||
test("test", /^|x*/, "t,e,s,t");
|
||||
test("test", /t*/, ",e,s,");
|
||||
test("xaabaax", /a*|b*/, "x,b,x");
|
||||
test("xaabaax", /a+|b+/, "x,,,x");
|
||||
test("xaabaax", /a+|b*/, "x,,,x");
|
||||
test("xaaxbaax", /b+|a+/, "x,x,,x");
|
||||
test("test", /^|t/, "tes,");
|
||||
test("test", /^|t/, "tes,");
|
||||
test("a,,b", /,/, "a,,b");
|
||||
test("ab", /a*/, ",b");
|
||||
test("aab", "a", ",,b");
|
||||
test("a", "a", ",");
|
||||
|
||||
function test_length(string, separator, len) {
|
||||
var r = string.split(separator);
|
||||
ok(r.length === len, "\"" + string + "\".split(" + separator + ").length = "
|
||||
+ r.length + " expected " + len);
|
||||
}
|
||||
|
||||
test_length("", /a*/, 0);
|
||||
test_length("", /a+/, 1);
|
||||
test_length("", "", 0);
|
||||
test_length("", "x", 1);
|
||||
|
||||
r = "1,2,3".split(undefined);
|
||||
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
|
||||
ok(r.length === 1, "r.length = " + r.length);
|
||||
|
|
Loading…
Reference in New Issue