From 34ae33738da2c433869e6b815eb089c52761ec65 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Fri, 22 Feb 2013 13:38:21 -0500 Subject: Patch 159: Validate all values passed to options (Moi_ioM) --- src/base/option.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/base/option.lua b/src/base/option.lua index 4243a42..b31dc3d 100644 --- a/src/base/option.lua +++ b/src/base/option.lua @@ -12,14 +12,14 @@ -- premake.option.list = { } - + -- -- Register a new option. -- -- @param opt -- The new option object. --- +-- function premake.option.add(opt) -- some sanity checking @@ -29,11 +29,11 @@ missing = field end end - + if (missing) then error("option needs a " .. missing, 3) end - + -- add it to the master list premake.option.list[opt.trigger] = opt end @@ -64,7 +64,7 @@ table.insert(keys, option.trigger) end table.sort(keys) - + local i = 0 return function() i = i + 1 @@ -89,18 +89,24 @@ if (not opt) then return false, "invalid option '" .. key .. "'" end - + -- does it need a value? if (opt.value and value == "") then return false, "no value specified for option '" .. key .. "'" end - + -- is the value allowed? - if (opt.allowed) then + if opt.allowed then + local found = false for _, match in ipairs(opt.allowed) do - if (match[1] == value) then return true end + if match[1] == value then + found = true + break + end + end + if not found then + return false, string.format("invalid value '%s' for option '%s'", value, key) end - return false, "invalid value '" .. value .. "' for option '" .. key .. "'" end end return true -- cgit v1.2.3