# HG changeset patch # User Kim Alvefur # Date 1483387476 -3600 # Node ID 623e23190c3e0402133e963e67f5ca735d327f1e # Parent a2625a36c092b484861f6f54374f5a6d6e6e14db mod_storage_appendmap: Escape Lua keywords diff -r a2625a36c092 -r 623e23190c3e mod_storage_appendmap/mod_storage_appendmap.lua --- a/mod_storage_appendmap/mod_storage_appendmap.lua Mon Jan 02 21:03:56 2017 +0100 +++ b/mod_storage_appendmap/mod_storage_appendmap.lua Mon Jan 02 21:04:36 2017 +0100 @@ -29,6 +29,18 @@ return env[key]; end +local keywords = { + ["do"] = true; ["and"] = true; ["else"] = true; ["break"] = true; + ["if"] = true; ["end"] = true; ["goto"] = true; ["false"] = true; + ["in"] = true; ["for"] = true; ["then"] = true; ["local"] = true; + ["or"] = true; ["nil"] = true; ["true"] = true; ["until"] = true; + ["elseif"] = true; ["function"] = true; ["not"] = true; + ["repeat"] = true; ["return"] = true; ["while"] = true; + + -- _ENV is not technically a keyword but we need to treat it as such + ["_ENV"] = true; +}; + function map:set_keys(user, keyvalues) local keys, values = {}, {}; if _VERSION == "Lua 5.1" then @@ -36,7 +48,7 @@ end for key, value in pairs(keyvalues) do module:log("debug", "user %s sets %q to %s", user, key, tostring(value)) - if type(key) ~= "string" or not key:find("^[%a_][%w_]*$") or key == "_ENV" then + if type(key) ~= "string" or not key:find("^[%a_][%w_]*$") or keywords[key] then key = "_ENV[" .. dump(key) .. "]"; end table.insert(keys, key);