Fix string.split returning an empty table if string starts with sepearator (#7827)

Calling string.split(":A:B:C:D", ":") returns an empty array.
This is due to first empty string not making repeat loop decreasing max_split which has a 0 value when reaching until.
Changing max_splits default value from -1 to -2 fixes that issue.
This commit is contained in:
Pierre-Yves Rollo 2018-11-01 21:07:01 +01:00 committed by Nils Dagsson Moskopp
parent b72c46443f
commit a1bcc6ba94
Signed by: erle
GPG Key ID: A3BC671C35191080
1 changed files with 1 additions and 1 deletions

View File

@ -166,7 +166,7 @@ end
--------------------------------------------------------------------------------
function string.split(str, delim, include_empty, max_splits, sep_is_pattern)
delim = delim or ","
max_splits = max_splits or -1
max_splits = max_splits or -2
local items = {}
local pos, len = 1, #str
local plain = not sep_is_pattern