forked from Mirrorlandia_minetest/minetest
Error when string.split is given empty separator (#13132)
This commit is contained in:
parent
a3177b89d8
commit
ab1fe80150
@ -170,6 +170,9 @@ end
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function string.split(str, delim, include_empty, max_splits, sep_is_pattern)
|
function string.split(str, delim, include_empty, max_splits, sep_is_pattern)
|
||||||
delim = delim or ","
|
delim = delim or ","
|
||||||
|
if delim == "" then
|
||||||
|
error("string.split separator is empty", 2)
|
||||||
|
end
|
||||||
max_splits = max_splits or -2
|
max_splits = max_splits or -2
|
||||||
local items = {}
|
local items = {}
|
||||||
local pos, len = 1, #str
|
local pos, len = 1, #str
|
||||||
|
@ -38,6 +38,12 @@ describe("string", function()
|
|||||||
assert.same({ "one", "two" }, string.split("one,two", ",", false, -1, true))
|
assert.same({ "one", "two" }, string.split("one,two", ",", false, -1, true))
|
||||||
assert.same({ "one", "two", "three" }, string.split("one2two3three", "%d", false, -1, true))
|
assert.same({ "one", "two", "three" }, string.split("one2two3three", "%d", false, -1, true))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("rejects empty separator", function()
|
||||||
|
assert.has.errors(function()
|
||||||
|
string.split("", "")
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -3623,7 +3623,7 @@ Helper functions
|
|||||||
* `math.round(x)`: Returns `x` rounded to the nearest integer.
|
* `math.round(x)`: Returns `x` rounded to the nearest integer.
|
||||||
* At a multiple of 0.5, rounds away from zero.
|
* At a multiple of 0.5, rounds away from zero.
|
||||||
* `string.split(str, separator, include_empty, max_splits, sep_is_pattern)`
|
* `string.split(str, separator, include_empty, max_splits, sep_is_pattern)`
|
||||||
* `separator`: string, default: `","`
|
* `separator`: string, cannot be empty, default: `","`
|
||||||
* `include_empty`: boolean, default: `false`
|
* `include_empty`: boolean, default: `false`
|
||||||
* `max_splits`: number, if it's negative, splits aren't limited,
|
* `max_splits`: number, if it's negative, splits aren't limited,
|
||||||
default: `-1`
|
default: `-1`
|
||||||
|
Loading…
Reference in New Issue
Block a user