diff options
author | Robert Zenz <Robert.Zenz@bonsaimind.org> | 2015-11-07 16:31:32 +0100 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2015-11-24 01:49:59 +0100 |
commit | 0cf15470fc16e1ebc13a7d8445cfd4278c3caf8b (patch) | |
tree | dc02b32b040b53c78ee437623b77c3bd681b7e4d /builtin | |
parent | c24f3b0a65afc7654a8377fde29dec0709b1fc49 (diff) | |
download | minetest-0cf15470fc16e1ebc13a7d8445cfd4278c3caf8b.tar.gz minetest-0cf15470fc16e1ebc13a7d8445cfd4278c3caf8b.tar.bz2 minetest-0cf15470fc16e1ebc13a7d8445cfd4278c3caf8b.zip |
Simplify regex used in check_modname_prefix and other improvements.
Simplified the regex used, added comments and changed the error message
to contain the correct mod name.
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/game/register.lua | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 840ade127..00bb23278 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -51,20 +51,24 @@ local forbidden_item_names = { local function check_modname_prefix(name) if name:sub(1,1) == ":" then - -- Escape the modname prefix enforcement mechanism + -- If the name starts with a colon, we can skip the modname prefix + -- mechanism. return name:sub(2) else - -- Modname prefix enforcement + -- Enforce that the name starts with the correct mod name. local expected_prefix = core.get_current_modname() .. ":" if name:sub(1, #expected_prefix) ~= expected_prefix then error("Name " .. name .. " does not follow naming conventions: " .. - "\"modname:\" or \":\" prefix required") + "\"" .. expected_prefix .. "\" or \":\" prefix required") end + + -- Enforce that the name only contains letters, numbers and underscores. local subname = name:sub(#expected_prefix+1) - if subname:find("[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]") then + if subname:find("[^%w_]") then error("Name " .. name .. " does not follow naming conventions: " .. "contains unallowed characters") end + return name end end |