Skip to content

Commit 93bdb5e

Browse files
committed
Making sure process*() isn't called recursively.
1 parent af5ae0e commit 93bdb5e

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

preprocess.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ local metaEnv = nil
196196
local dummyEnv = {}
197197

198198
-- Controlled by processFileOrString():
199-
local current_parsingAndMeta_isDebug = false
199+
local current_parsingAndMeta_isProcessing = false
200+
local current_parsingAndMeta_isDebug = false
200201

201202
-- Controlled by _processFileOrString():
202203
local current_anytime_isRunningMeta = false
@@ -3642,15 +3643,21 @@ local function _processFileOrString(params, isFile)
36423643
end
36433644

36443645
local function processFileOrString(params, isFile)
3646+
if current_parsingAndMeta_isProcessing then
3647+
error("Cannot process recursively.", 3)
3648+
end
3649+
36453650
-- local startTime = os.clock() -- DEBUG
36463651
local returnValues = nil
36473652

3648-
current_parsingAndMeta_isDebug = params.debug
3653+
current_parsingAndMeta_isProcessing = true
3654+
current_parsingAndMeta_isDebug = params.debug
36493655

36503656
local xpcallOk, xpcallErr = xpcall(
36513657
function()
36523658
returnValues = pack(_processFileOrString(params, isFile))
36533659
end,
3660+
36543661
function(err)
36553662
if type(err) == "string" and err:find("\0", 1, true) then
36563663
printError(tryToFormatError(cleanError(err)))
@@ -3669,7 +3676,8 @@ local function processFileOrString(params, isFile)
36693676
end
36703677
)
36713678

3672-
current_parsingAndMeta_isDebug = false
3679+
current_parsingAndMeta_isProcessing = false
3680+
current_parsingAndMeta_isDebug = false
36733681

36743682
-- Cleanup in case an error happened.
36753683
current_anytime_isRunningMeta = false

tests/suite.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,15 @@ doTest("Indentation", function()
708708
local indent, expect = pp.getIndentation("\t \t", 4), 12 ; if indent ~= expect then error(expect.." "..indent) end
709709
end)
710710

711+
doTest("Recursive processing", function()
712+
local pp = ppChunk()
713+
pp.metaEnvironment.pp = pp
714+
715+
assert(not pp.processString{ code=[[
716+
!pp.processString{ code="" } -- Not supported!
717+
]]})
718+
end)
719+
711720
doTest("Misc.", function()
712721
local pp = ppChunk()
713722

0 commit comments

Comments
 (0)