[PATCH v2 0/1] MR10309: vbscript: Split() should return an empty array for empty strings.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=58398 -- v2: vbscript: Split() should return an empty array for empty strings. https://gitlab.winehq.org/wine/wine/-/merge_requests/10309
From: Francis De Brabandere <francisdb@gmail.com> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=58398 --- dlls/vbscript/global.c | 30 ++++++++++++++++++++---------- dlls/vbscript/tests/api.vbs | 4 ++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 965a6233bc2..f38ff895ef7 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -2727,7 +2727,7 @@ static HRESULT Global_Split(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, if(V_VT(args+1) != VT_BSTR) { hres = to_string(args+1, &delimiter); if(FAILED(hres)) - goto error; + goto done; }else { delimiter = V_BSTR(args+1); } @@ -2737,10 +2737,10 @@ static HRESULT Global_Split(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, if(args_cnt > 2) { hres = to_int(args+2, &max); if(FAILED(hres)) - goto error; + goto done; if (max < -1) { hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); - goto error; + goto done; } }else { max = -1; @@ -2749,10 +2749,10 @@ static HRESULT Global_Split(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, if(args_cnt == 4) { hres = to_int(args+3, &mode); if(FAILED(hres)) - goto error; + goto done; if (mode != 0 && mode != 1) { hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); - goto error; + goto done; } }else { mode = 0; @@ -2761,12 +2761,22 @@ static HRESULT Global_Split(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, start = 0; len = SysStringLen(string); + + if(!len) { + bounds.lLbound = 0; + bounds.cElements = 0; + sa = SafeArrayCreate(VT_VARIANT, 1, &bounds); + if(!sa) + hres = E_OUTOFMEMORY; + goto done; + } + count = 0; indices = malloc( indices_max * sizeof(int)); if(!indices) { hres = E_OUTOFMEMORY; - goto error; + goto done; } while(1) { @@ -2786,7 +2796,7 @@ static HRESULT Global_Split(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, new_indices = realloc(indices, indices_max * 2 * sizeof(int)); if(!new_indices) { hres = E_OUTOFMEMORY; - goto error; + goto done; } indices = new_indices; indices_max *= 2; @@ -2803,11 +2813,11 @@ static HRESULT Global_Split(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, sa = SafeArrayCreate( VT_VARIANT, 1, &bounds); if (!sa) { hres = E_OUTOFMEMORY; - goto error; + goto done; } hres = SafeArrayAccessData(sa, (void**)&data); if(FAILED(hres)) { - goto error; + goto done; } start = 0; @@ -2823,7 +2833,7 @@ static HRESULT Global_Split(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, } SafeArrayUnaccessData(sa); -error: +done: if(SUCCEEDED(hres) && res) { V_VT(res) = VT_ARRAY|VT_VARIANT; V_ARRAY(res) = sa; diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index 319ef90e70f..e18d887306b 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -830,6 +830,10 @@ Call ok(x(2) = "def", "Split(""abc--def"",""-"")(2)=" & x(2)) x = Split("abcdefghi","def") Call ok(x(0) = "abc", "Split(""abcdefghi"",""def"")(0)=" & x(0)) Call ok(x(1) = "ghi", "Split(""abcdefghi"",""def"")(1)=" & x(1)) +x = Split("", ",") +Call ok(UBound(x) = -1, "UBound(Split("""","",""))=" & UBound(x)) +x = Split("") +Call ok(UBound(x) = -1, "UBound(Split(""""))=" & UBound(x)) x = Split("12345",3) Call ok(x(0) = "12", "Split(""12345"",3)(0)=" & x(0)) Call ok(x(1) = "45", "Split(""12345"",3)(1)=" & x(1)) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10309
On Thu Mar 12 13:47:52 2026 +0000, Francis De Brabandere wrote:
changed this line in [version 2 of the diff](/wine/wine/-/merge_requests/10309/diffs?diff_id=250414&start_sha=6c745242b3c357faab162cda8fb9702ee8e54ff7#f705ff2124202b08096a71599eedf1d31dff92a3_2771_2771) Is this ok? I will also update the commits on my other PR's.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/10309#note_131992
On Thu Mar 12 13:51:45 2026 +0000, Francis De Brabandere wrote:
Is this ok? I will also update the commits on my other PR's. all updated
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/10309#note_132014
This merge request was approved by Jacek Caban. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10309
participants (3)
-
Francis De Brabandere -
Francis De Brabandere (@francisdb) -
Jacek Caban (@jacek)