4 Commits

Author SHA1 Message Date
Enrique García Cota
fd442fd395 docs(changelog) document 1.0.1 2021-01-07 18:43:44 +01:00
Enrique García Cota
3f11f19ba3 tests - add test for overriding base env with false 2021-01-07 18:32:29 +01:00
eskerda
26553beec7 fix(sandbox) fix false on passed_env
passed_env[k] = false would set BASE_ENV[k]
2021-01-07 18:28:16 +01:00
Enrique García Cota
e28e0bef65 chore - publish rockspec and add luarocks instructions 2021-01-07 11:38:37 +01:00
5 changed files with 23 additions and 6 deletions

View File

@@ -1,4 +1,8 @@
v1.0.0 (2021-01)
# v1.0.1 (2021-01)
- Fix a bug in which the base environment wasn't overrideable with `false`
# v1.0.0 (2021-01)
- Added support for all major versions of PUC Rio Lua and LuaJIT
- Only Lua strings are admitted now, "naked Lua" functions are not permitted any more
@@ -8,6 +12,6 @@ v1.0.0 (2021-01)
- Environments can have metatables with indexes, and they are respected
- Environments can override the base environment
v0.5.0 (2013)
# v0.5.0 (2013)
Initial version

View File

@@ -164,6 +164,10 @@ Installation
Just copy sandbox.lua wherever you need it.
Alternatively, you can use luarocks:
luarocks install kikito/sandbox
License
=======

View File

@@ -1,10 +1,10 @@
package = "sandbox.lua"
package = "sandbox"
version = "0.0.1-0"
version = "1.0.0-0"
source = {
url = "git://github.com/kikito/sandbox.lua.git",
tag = "0.0.1"
tag = "v1.0.0"
}
description = {

View File

@@ -134,7 +134,11 @@ function sandbox.protect(code, options)
local env = {}
for k, v in pairs(BASE_ENV) do
local pv = passed_env[k]
env[k] = pv ~= nil and pv or v
if pv ~= nil then
env[k] = pv
else
env[k] = v
end
end
setmetatable(env, { __index = options.env })
env._G = env

View File

@@ -135,6 +135,11 @@ describe('sandbox.run', function()
local env = { tostring = function(x) return "hello " .. x end }
assert.equal("hello peter", sandbox.run("return tostring('peter')", { env = env }))
end)
it('can override the base env with false', function()
local env = { tostring = false }
assert.equal(false, sandbox.run("return tostring", { env = env }))
end)
end)
end)