Skip to content

Commit 5fadbeb

Browse files
committed
COMMON: SPLIT with empty input now gives zero length output #147
1 parent e49e432 commit 5fadbeb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

samples/distro-examples/tests/split-join.bas

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,12 @@ if (9 != ubound(a)) then
6060
throw "Final empty entry was ignored"
6161
endif
6262

63+
row = ""
64+
split row, ":", fields()
65+
if (len(fields) != 0) then throw "Empty input gave non-empty output"
66+
67+
s="$$$1$2$3$4$5$$$6$7$"
68+
split s, "!@#$%^", a
69+
if (ubound(a) - lbound(a) != len(a) - 1) then throw "Dimension error"
70+
71+

src/common/blib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,10 +2249,11 @@ void cmd_wsplit() {
22492249
elem_p = v_elem(var_p, count);
22502250
if (*ps) {
22512251
v_setstr(elem_p, ps);
2252-
} else {
2252+
count++;
2253+
} else if (count) {
22532254
v_setstr(elem_p, "");
2255+
count++;
22542256
}
2255-
count++;
22562257

22572258
// final resize
22582259
v_resize_array(var_p, count);

0 commit comments

Comments
 (0)