Jacek Caban : jscript: Don' t skip empty strings in String.prototype.split in ES5 mode.
Alexandre Julliard
julliard at winehq.org
Mon Apr 22 16:30:38 CDT 2019
Module: wine
Branch: master
Commit: 88d2576ae71a8727b658a70200f382f66cb651c3
URL: https://source.winehq.org/git/wine.git/?a=commit;h=88d2576ae71a8727b658a70200f382f66cb651c3
Author: Jacek Caban <jacek at codeweavers.com>
Date: Mon Apr 22 13:04:45 2019 +0200
jscript: Don't skip empty strings in String.prototype.split in ES5 mode.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/jscript/string.c | 4 ++--
dlls/mshtml/tests/es5.js | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c
index d88ed1c..5b00cd6 100644
--- a/dlls/jscript/string.c
+++ b/dlls/jscript/string.c
@@ -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) {
diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js
index 7afdf97..69c0d86 100644
--- a/dlls/mshtml/tests/es5.js
+++ b/dlls/mshtml/tests/es5.js
@@ -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);
More information about the wine-cvs
mailing list