-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added configuration functions to disable and sandbox string lambdas
- Loading branch information
1 parent
e34bf7a
commit a66d599
Showing
7 changed files
with
127 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
local function getLuaVersion() | ||
local major, minor = _VERSION:match("Lua (%d)%.(%d)") | ||
local major, minor = tonumber(major), tonumber(minor) | ||
|
||
return major, minor | ||
end | ||
|
||
return { | ||
getLuaVersion = getLuaVersion, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
describe("#configuration function disableLambdas", function() | ||
it("disallows the use of lambdas", function() | ||
local linq = require("lazylualinq").disableLambdas() | ||
local seq = linq {1, 2, 3} | ||
|
||
assert.has_error(function() | ||
seq:select("v => v * 2") | ||
end, "Lambdas have been disabled") | ||
end) | ||
|
||
it("disables linq.lambda", function() | ||
local linq = require("lazylualinq").disableLambdas() | ||
|
||
assert.has_error(function() | ||
linq.lambda("v => v * 2") | ||
end, "Lambdas have been disabled") | ||
end) | ||
|
||
-- It could be nice to allow this (though we'd likely want lambdas disabled by default then). | ||
-- For the moment, though, this is how it is. | ||
-- If we allow multiple different configurations, though, we'd need the module to return a kind of 'module factory' | ||
-- (which would force users to do something like `local linq = require("lazylualinq").build()`) | ||
it("disables lambdas globally", function() | ||
local linq = require("lazylualinq").disableLambdas() | ||
local safeLinq = require("lazylualinq") | ||
|
||
assert.has_error(function() | ||
safeLinq.lambda("v => v * 2") | ||
end, "Lambdas have been disabled") | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
local helpers = require("test._helpers") | ||
|
||
describe("#configuration function withLambdaEnv", function() | ||
it("allows access to the global environment if not called", function() | ||
local linq = require("lazylualinq") | ||
local func = linq.lambda("os") | ||
local ret = func() | ||
|
||
assert.is_equal(os, ret) | ||
end) | ||
|
||
it("can be used to sandbox lambdas", function() | ||
local linq = require("lazylualinq").withLambdaEnv({}) | ||
local func = linq.lambda("os") | ||
|
||
local ret = func() | ||
|
||
-- os is not available within the lambda | ||
assert.is_nil(ret) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters