aboutsummaryrefslogtreecommitdiff
path: root/pandoc-lua-engine/test/lua/module/pandoc.lua
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2025-05-13 23:21:28 +0200
committerAlbert Krewinkel <[email protected]>2025-05-13 23:38:36 +0200
commit31f74fac065023e1accc686753dc6216edd4c9c4 (patch)
tree779f1800bed4d8869190143e6b0d0aea7ffe595d /pandoc-lua-engine/test/lua/module/pandoc.lua
parent21966099896ecc612786f4ba4bb6f08fcfff5253 (diff)
Lua: support sandboxed parsing with `pandoc.read`.
The function `pandoc.read` is now taking an optional fourth parameter that specifies the environment in which the parser will be run. Passing the string `sandbox` as the argument causes the reader to run in a sandbox, thereby preventing all access to the network and file system. Closes: #10831
Diffstat (limited to 'pandoc-lua-engine/test/lua/module/pandoc.lua')
-rw-r--r--pandoc-lua-engine/test/lua/module/pandoc.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/pandoc-lua-engine/test/lua/module/pandoc.lua b/pandoc-lua-engine/test/lua/module/pandoc.lua
index 5df547d24..3db58c0f8 100644
--- a/pandoc-lua-engine/test/lua/module/pandoc.lua
+++ b/pandoc-lua-engine/test/lua/module/pandoc.lua
@@ -293,6 +293,40 @@ return {
'Unknown input format nosuchreader'
)
end),
+ group 'read_env' {
+ test('images are added to the mediabag', function ()
+ local epub = io.open('lua/module/sample.epub', 'rb'):read('a')
+ local _ = pandoc.read(epub, 'epub')
+ assert.are_equal(
+ #pandoc.mediabag.list(),
+ 1
+ )
+ end),
+ test('images from EPUB are added when using the sandbox', function ()
+ local epub = io.open('lua/module/sample.epub', 'rb'):read('a')
+ local _ = pandoc.read(epub, 'epub', nil, 'sandbox')
+ assert.are_equal(
+ #pandoc.mediabag.list(),
+ 1
+ )
+ end),
+ test('includes work in global env', function ()
+ local tex = '\\include{lua/module/include.tex}'
+ local doc = pandoc.read(tex, 'latex', nil, 'global')
+ assert.are_equal(
+ doc.blocks,
+ pandoc.Blocks{pandoc.Para 'included'}
+ )
+ end),
+ test('sandbox disallows access to the filesystem', function ()
+ local tex = '\\include{lua/module/include.tex}'
+ local doc = pandoc.read(tex, 'latex', nil, 'sandbox')
+ assert.are_equal(
+ doc.blocks,
+ pandoc.Blocks{}
+ )
+ end),
+ },
group 'extensions' {
test('string spec', function ()
local doc = pandoc.read('"vice versa"', 'markdown-smart')