diff options
-rw-r--r-- | lib.c | 5 | ||||
-rw-r--r-- | tests/custom/03_bugs/13_split_by_string_leading_trailing | 11 |
2 files changed, 13 insertions, 3 deletions
@@ -967,7 +967,7 @@ uc_split(uc_vm *vm, size_t nargs) else if (ucv_type(sep) == UC_STRING) { sepstr = ucv_string_get(sep); - for (p = splitstr + (*sepstr ? 1 : 0), seplen = strlen(sepstr); *p; p++) { + for (p = splitstr, seplen = strlen(sepstr); *p; p++) { if (!strncmp(p, sepstr, seplen)) { if (*sepstr || p > splitstr) ucv_array_push(arr, ucv_string_new_length(splitstr, p - splitstr)); @@ -977,8 +977,7 @@ uc_split(uc_vm *vm, size_t nargs) } } - if (*splitstr) - ucv_array_push(arr, ucv_string_new_length(splitstr, p - splitstr)); + ucv_array_push(arr, ucv_string_new_length(splitstr, p - splitstr)); } else { ucv_put(arr); diff --git a/tests/custom/03_bugs/13_split_by_string_leading_trailing b/tests/custom/03_bugs/13_split_by_string_leading_trailing new file mode 100644 index 0000000..10a6062 --- /dev/null +++ b/tests/custom/03_bugs/13_split_by_string_leading_trailing @@ -0,0 +1,11 @@ +When splitting a string, the existing uc_split() implementation failed +to produce an empty leading and trailing result array element when the +subject string started or ended with a delimitter. + +-- Expect stdout -- +[ "", "foo", "" ] +-- End -- + +-- Testcase -- +{{ split("/foo/", "/") }} +-- End -- |