check for negative max_split value

This commit is contained in:
Jeremy S. Postelnek 2021-12-24 13:19:12 -05:00 committed by GitHub
parent 660ae8ca52
commit 23bc392b6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,10 @@ function stringx.split(self, delim, max_split)
assert:type(delim, "string", "stringx.split - delim", 1) assert:type(delim, "string", "stringx.split - delim", 1)
assert:type(max_split, "number", "stringx.split - max_split", 1) assert:type(max_split, "number", "stringx.split - max_split", 1)
if max_split then
assert(max_split > 0, "max_split must be positive!")
end
--we try to create as little garbage as possible! --we try to create as little garbage as possible!
--only one table to contain the result, plus the split strings. --only one table to contain the result, plus the split strings.
--so we do two passes, and work with the bytes underlying the string --so we do two passes, and work with the bytes underlying the string