diff --git a/sandbox.lua b/sandbox.lua index ff0a8d4..b138db7 100644 --- a/sandbox.lua +++ b/sandbox.lua @@ -120,19 +120,26 @@ function sandbox.protect(f, options) options = options or {} - local quota = options.quota or 500000 + local quota = false + if options.quota ~= false then + quota = options.quota or 500000 + end + local env = merge(options.env or {}, BASE_ENV) env._G = env._G or env setfenv(f, env) return function(...) - local timeout = function() - cleanup() - error('Quota exceeded: ' .. tostring(quota)) + + if quota then + local timeout = function() + cleanup() + error('Quota exceeded: ' .. tostring(quota)) + end + sethook(timeout, "", quota) end - sethook(timeout, "", quota) string.rep = nil local ok, result = pcall(f, ...) diff --git a/spec/sandbox_spec.lua b/spec/sandbox_spec.lua index e81e819..7191ed5 100644 --- a/spec/sandbox_spec.lua +++ b/spec/sandbox_spec.lua @@ -83,6 +83,10 @@ describe('sandbox.run', function() assert_error(function() sandbox.run("for i=1,100 do end", {quota = 20}) end) end) + it('does not use quotes if the quote param is false', function() + assert_not_error(function() sandbox.run("for i=1,1000000 do end", {quota = false}) end) + end) + end)