Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Perkins <starkos@industriousone.com>2013-02-22 22:38:21 +0400
committerJason Perkins <starkos@industriousone.com>2013-02-22 22:38:21 +0400
commit34ae33738da2c433869e6b815eb089c52761ec65 (patch)
tree480eb4d5f4ac9756e23932c66e99dff281b408a0
parent8c123337a2682c4a681dc6124a73f53e11c74059 (diff)
Patch 159: Validate all values passed to options (Moi_ioM)
-rw-r--r--CHANGES.txt1
-rw-r--r--src/base/option.lua26
2 files changed, 17 insertions, 10 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index f0e8937..9007bcf 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -70,6 +70,7 @@
* Fix linking to external libraries outside of project folder
* Improve processing of ld.so.conf (Cameron Hart)
* Patch 154: Fix .def file support for VS2010 (Riccardo Ghetta)
+* Patch 159: Validate all values passed to options (Moi_ioM)
-------
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