libs/core: Fixed luci.util.split
authorSteven Barth <steven@midlink.org>
Sat, 5 Jul 2008 16:27:24 +0000 (16:27 +0000)
committerSteven Barth <steven@midlink.org>
Sat, 5 Jul 2008 16:27:24 +0000 (16:27 +0000)
libs/core/luasrc/util.lua

index 76e382b45ac536c2ec2a9552f2be2d5e87c6624b..443d5f3032c58cbce2cd0d9c7ee07fd4338020ba 100644 (file)
@@ -186,8 +186,12 @@ function split(str, pat, max, regex)
        
        repeat
                local s, e = str:find(pat, c, not regex)
        
        repeat
                local s, e = str:find(pat, c, not regex)
-               table.insert(t, str:sub(c, s and s - 1))
                max = max - 1
                max = max - 1
+               if s and max < 0 then
+                       table.insert(t, str:sub(c))
+               else
+                       table.insert(t, str:sub(c, s and s - 1))
+               end
                c = e and e + 1 or #str + 1
        until not s or max < 0
        
                c = e and e + 1 or #str + 1
        until not s or max < 0