From e18a5566430a6e3cd1eb0014e45535e2309eacf2 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Wed, 10 Feb 2016 13:49:31 -0700 Subject: [PATCH] Prevent nil from crashing the lua script. --- .../install/scripts/resources/functions/explode.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/install/scripts/resources/functions/explode.lua b/resources/install/scripts/resources/functions/explode.lua index 4355a643e8..f6965f79df 100644 --- a/resources/install/scripts/resources/functions/explode.lua +++ b/resources/install/scripts/resources/functions/explode.lua @@ -2,10 +2,12 @@ --add the explode function function explode ( seperator, str ) local pos, arr = 0, {} - for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found - table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider - pos = sp + 1 -- jump past current divider + if (seperator ~= nil and str ~= nil) then + for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found + table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider + pos = sp + 1 -- jump past current divider + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider return arr end \ No newline at end of file