Skip to content

Commit

Permalink
fix(stringx) do not append empty string if hit number of matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Apr 28, 2019
1 parent f9f06de commit 66e8599
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
- `types.is_empty` would return true on spaces always, indepedent of the parameter
- `types.to_bool` will now compare case-insensitive for the extra passed strings
- `app.require_here` will now properly handle an absolute base path
- `stringx.split` will no longer append an empty match if the number of requested
elements has already been reached.

## 1.6.0 (2018-11-23)

Expand Down
4 changes: 3 additions & 1 deletion lua/pl/stringx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ function stringx.split(s,re,n)
plain = false
end
local res = usplit(s,re,plain,n)
if re and re ~= '' and find(s,re,-#re,true) then
if re and re ~= '' and
find(s,re,-#re,true) and
(n or math.huge) > #res then
res[#res+1] = ""
end
return makelist(res)
Expand Down
1 change: 1 addition & 0 deletions tests/test-stringx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ asserteq(split('a', 'a'), {''})
asserteq(split(' 1 2 3 '),{'1','2','3'})
asserteq(split('a*bb*c*ddd','*'),{'a','bb','c','ddd'})
asserteq(split('dog:fred:bonzo:alice',':',3), {'dog','fred','bonzo:alice'})
asserteq(split('dog:fred:bonzo:alice:',':',3), {'dog','fred','bonzo:alice:'})
asserteq(split('///','/'),{'','','',''})
-- capitalize
asserteq(T(stringx.capitalize('')), T(''))
Expand Down

0 comments on commit 66e8599

Please sign in to comment.