Skip to content

Commit

Permalink
Fix string.split returning an empty table if string starts with sepea…
Browse files Browse the repository at this point in the history
…rator (#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.
  • Loading branch information
pyrollo authored and SmallJoker committed Nov 1, 2018
1 parent 4d4bfb1 commit 0e306c0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion builtin/common/misc_helpers.lua
Expand Up @@ -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
Expand Down

0 comments on commit 0e306c0

Please sign in to comment.