diff options
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/common/misc_helpers.lua | 3 | ||||
-rw-r--r-- | builtin/common/tests/misc_helpers_spec.lua | 6 |
2 files changed, 9 insertions, 0 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index 1a2b9500a..90ac2ae4e 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -170,6 +170,9 @@ end -------------------------------------------------------------------------------- function string.split(str, delim, include_empty, max_splits, sep_is_pattern) delim = delim or "," + if delim == "" then + error("string.split separator is empty", 2) + end max_splits = max_splits or -2 local items = {} local pos, len = 1, #str diff --git a/builtin/common/tests/misc_helpers_spec.lua b/builtin/common/tests/misc_helpers_spec.lua index ff0f0298a..73a66737f 100644 --- a/builtin/common/tests/misc_helpers_spec.lua +++ b/builtin/common/tests/misc_helpers_spec.lua @@ -38,6 +38,12 @@ describe("string", function() assert.same({ "one", "two" }, string.split("one,two", ",", false, -1, true)) assert.same({ "one", "two", "three" }, string.split("one2two3three", "%d", false, -1, true)) end) + + it("rejects empty separator", function() + assert.has.errors(function() + string.split("", "") + end) + end) end) end) |