From 57d66be7850b865ef20fdffe5622f4a7f4c71fef Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 20 Sep 2014 08:13:49 -0700 Subject: [PATCH] Fix skipping trailing empty segments in re.split --- automation/include/aegisub/re.moon | 2 +- automation/tests/modules/re.moon | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/automation/include/aegisub/re.moon b/automation/include/aegisub/re.moon index c487c3424..681786eb1 100644 --- a/automation/include/aegisub/re.moon +++ b/automation/include/aegisub/re.moon @@ -165,7 +165,7 @@ class RegEx if not first or first > str\len() ret = str\sub prev, str\len() str = nil - return ret + return if skip_empty and ret\len() == 0 then nil else ret ret = str\sub prev, first - 1 prev = last + 1 diff --git a/automation/tests/modules/re.moon b/automation/tests/modules/re.moon index 34e943685..4b070ccc0 100644 --- a/automation/tests/modules/re.moon +++ b/automation/tests/modules/re.moon @@ -170,6 +170,11 @@ describe 'split', -> assert.is.equal 'b', res[2] assert.is.equal 'c', res[3] + it 'should return an empty table when given only empty segments', -> + res = re.split ',,,', ',', true + assert.is.not.nil res + assert.is.equal 0, #res + it 'should be able to split on word boundaries', -> res = re.split 'aa bb cc', '\\b', true assert.is.not.nil res